[R] system2 commands with backslash

Zev Ross zev at zevross.com
Thu Oct 10 17:16:54 CEST 2013


Hi All,

I'm trying to edit a file in place using system2 and sed from within R. 
I can get my command to work unless there is a backslash in the command 
in which case I'm warned about an "unrecognized escape". So, for example:

system2("sed -i s/oldword/newword/g d:/junk/x/test.tex") # works fine
system2("sed -i s/oldword\s/newword/g d:/junk/x/test.tex") # does not 
work in R (the command works on the command line)

I've experimented with double slashes to escape the \s, I've tried the 
"shell" command, I've tried experimenting with shQuote and can't seem to 
get around the "unrecognized escape" issue.

By the way, it would be preferable to have a solution that avoided using 
double backslashes etc because, unfortunately, in my real-world example, 
I'm actually replacing double slashes and would prefer not to have 
quadruple slashes etc.

I'm using Windows 7, 64 bit.

Zev

-- 
Zev Ross
ZevRoss Spatial Analysis
120 N Aurora, Suite 3A
Ithaca, NY 14850
607-277-0004 (phone)
zev at zevross.com



More information about the R-help mailing list