[R] system2 commands with backslash

David Winsemius dwinsemius at comcast.net
Fri Oct 11 17:58:56 CEST 2013


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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list