system2("sed", args=c("-i", "s/oldword\\s/newword/g", "d:/junk/x/test.tex"))
/Henrik
On Fri, Oct 11, 2013 at 8:58 AM, David Winsemius <dwinsemius at comcast.net> wrote:
On Oct 10, 2013, at 8:16 AM, Zev Ross wrote:
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,
Wouldn't you want to double the backslashes instead?
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