Pass a vector to paste function in R

Viewed 33

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

1 Answers

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"
Related