[Rd] [R] shQuote and cat

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Thu Jul 24 09:38:25 CEST 2008

Duncan Murdoch wrote:
> Vadim Organovich wrote:
>> It is precizely a shell command that I am trying to generate. To be
>> specific let's try to have R 'output' the following shell command:
>> 'echo "\"a\""'. This is is a valid command, at least in bash:
>> bash-3.2$ echo "\"a\""
>> "a"
>> Now in R:
>>> x <- 'echo "\"a\""'
>>> cat(x, '\n')
>> echo ""a""
>>> cat(shQuote(x), '\n')
>> "echo \"\"a\"\""
>> Whichever way you do it it is not right. Again I think cat('echo
>> "\"a\""') should be printing *echo "\"a\""* (asterics are not a part
>> of the output)
try this:

(x = 'echo "\\"a\\""') # or x = 'echo \"\\\"a\\\"\"')
[1] "echo \"\\\"a\\\"\""

cat(x, "\n")
# echo "\"a\""

as desired.  you need to backslash the backslash.


More information about the R-devel mailing list