Add quotation mark to vector in R

Just wondering if there is a shortcut in R to add a quotation mark to the vector? Thus, it will be like c (lemon, orange, apple) to c ("lemon", "orange", "apple"), without going to each element manually to change it, because sometimes many elements can be in the vector . Thanks.

+2
source share
2 answers

You may try

 as.character(quote(c(lemon, orange, apple)))[-1]

Or another option suggested by @MrFlick in the comments

 as.character(expression(lemon, orange, apple))
+7
source
v = c("lemon", "orange", "apple")
v = paste0('"', v, '"')
# use cat in this case to see what "really" there
# print will show the quotes escaped with backslashes
cat(v)
## "lemon" "orange" "apple"
+1
source

All Articles