Home > Software design >  Pass a vector to paste function in R
Pass a vector to paste function in R

Time:06-29

I have a plot in my shiny app which I would like to make a title based on user selection. Let say my input$project has 2 values a and b.

paste("Projects",input$project)

"Projects :  a" "Projects :  b"

My desired output is "

"Projects :  a,b"

Which apparently I can not get it via paste function

CodePudding user response:

A possible solution:

x <- letters[1:2]
paste("Projects: ", paste(x, collapse = ", "))

#> [1] "Projects:  a, b"

Or even shorter with toString, as suggested below by @ThomasIsCoding, to whom I thank:

x <- letters[1:2]
paste("Projects: ", toString(x))

#> [1] "Projects:  a, b"

CodePudding user response:

Use

paste("Projects: ",paste(input$project , collapse = ",")) 
  • Related