Atirag
Atirag

Reputation: 1750

Adding double quotes to string in R

How can I add double quotes to a string taken from a vector in R?

I tried using paste but it doesn't work very well

kg_name=paste("\"",k_groups[i,],"\"")

lets say the value of k_groups[i,] is blah, so I'm looking for this result

"blah"

but the result is

"\" blah \""

Upvotes: 13

Views: 26384

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 270195

Try shQuote

shQuote("blah")
# [1] "\"blah\""

The above will work on Windows. Use shQuote("blah", "cmd") if you need it to work the same way giving double quotes on all operating systems.

Upvotes: 17

Related Questions