[R] How to create a string containing '\/' to be used with SED?

ikarus gianni at idsia.ch
Wed Nov 26 04:50:17 CET 2008

Hi guys,
I've been struggling to find a solution to the following issue:
I need to change strings in .ini files that are given in input to a program
whose output is processed by R. The strings to be changed looks like: 
"instance = /home/TSPFiles/TSPLIB/berlin52.tsp" 

I normally use Sed for this kind of things. So, inside R I'd like to write
something like:

 command <- paste("sed -i 's/^instance .*/instance = ", data$instancePath,
                   data$newInstance, "/' ", configurationFile, sep = "")

This will overwrite the line starting with "instance " using "instance =
In the example I gave, data$instancePath = /home/TSPFiles/TSPLIB/ and 
data$newInstance = berlin52.tsp

The problem is that I need to pass the above path string to sed in the form:

However, I couldn't find a way to "create" such a string in R. I tried in
several different ways,
but it always complains saying that '\/' is an unrecognized escape!
Any suggestion? 

View this message in context: http://www.nabble.com/How-to-create-a-string-containing-%27%5C-%27-to-be-used-with-SED--tp20694319p20694319.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list