[R] How to replace slashes with back slashes
Jean Eid
jeaneid at chass.utoronto.ca
Wed Jan 19 15:16:26 CET 2005
try
sink("filename")
cat(paste(gsub('/', '\\\\', 'c:/dir1/dir2/file.ext'),"\n",gsub('/',
'\\\\', 'c:/dir1/dir2/file.ext'),"\n" ))
sink()
the idea is to use cat,
instead of paste you can do a for loop where you cat the string into the
sinked file
On Wed, 19 Jan 2005, Joerg Klausen wrote:
> Dear R-helpers
>
> I am running R2.0.0 under Windows 2000. I am compiling a number of file paths into a simple text file that will be read by some other software we use. Unfortunately, it can only handle file paths with back slashes (MS Windows convention), and from R, I get file paths with forward slashes. The following didn't work.
>
> > gsub('/', '\\', 'c:/dir1/dir2/file.ext')
> [1] "c:dir1dir2file.ext"
> > gsub('/', '\\\\', 'c:/dir1/dir2/file.ext')
> [1] "c:\\dir1\\dir2\\file.ext"
>
> I have tried to find an answer on R-help, but didn't ;-(
>
> Thanks for helping me,
> Kind regards,
> Jörg
>
> Dr. Jörg Klausen phone : +41 (0)44 823 41 27
> EMPA (134)/GAW/QA-SAC fax : +41 (0)44 821 62 44
> Überlandstrasse 129 mailto: joerg.klausen at empa.ch
> CH-8600 Dübendorf http://www.empa.ch/gaw
> Switzerland http://www.empa.ch/gaw/gawsis
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list