From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Thu Jul 24 09:38:25 2008
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Thu, 24 Jul 2008 09:38:25 +0200
Subject: [Rd] [R] shQuote and cat
In-Reply-To: <4887C6F4.800@stats.uwo.ca>
References: <22D850BC39A25742977325ADDE208E770266956391@chiexchange02.w2k.jumptrading.com>,
	<4887741D.9030804@stats.uwo.ca>	<22D850BC39A25742977325ADDE208E770266956392@chiexchange02.w2k.jumptrading.com>,
	<488788AD.1050605@stats.uwo.ca>	<22D850BC39A25742977325ADDE208E770266956393@chiexchange02.w2k.jumptrading.com>
	<4887C6F4.800@stats.uwo.ca>
Message-ID: <48883171.8030404@idi.ntnu.no>

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.

vQ



[Rd] [R] shQuote and cat
Wacek Kusnierczyk