Haribo
Haribo

Reputation: 2226

Pass a vector to paste function in R

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

Upvotes: 2

Views: 206

Answers (1)

PaulS
PaulS

Reputation: 25323

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"

Upvotes: 3

Related Questions