How to print " around my text using sprintf in R?
Example:
Name<-"X"
sprintf({"%s"},Name)
which the output is:
[1] "X"
But I need
[1] ""X""
How to print " around my text using sprintf in R?
Example:
Name<-"X"
sprintf({"%s"},Name)
which the output is:
[1] "X"
But I need
[1] ""X""
 
    
    I think what you want is shQuote You can do
shQuote(Name)
# [1] "\"X\""
Note that R needs to escape the inner quotes in the console. It will not print out something that looks like ""X"". But if you cat the values the slashes aren't there
cat(shQuote(Name))
# "X"
 
    
    I'm not sure if another option will help you. But you can consider it:
The option could be:
Name<-"X"
#> sprintf("'%s'",Name)
#[1] "'X'"
