[R] \ escape sequence and windows path

David L Carlson dcarlson at tamu.edu
Tue May 20 17:04:45 CEST 2014


Annoying but easy. Would this work for you?

y <- gsub("\\\\", "/", readline())
C:\foo1\foo2\
> y
[1] "C:/foo1/foo2/"

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Knut Krueger
Sent: Tuesday, May 20, 2014 9:54 AM
To: 'R R-help'
Subject: Re: [R] \ escape sequence and windows path

Am 20.05.2014 15:22, schrieb Jeff Newmiller:
> Most importantly, "\\" is a string literal containing ONE backslash character. Yes you can create strings in R source code that represent Windows-style paths, but they must APPEAR different in that context. You may find it helpful to know that the print function can output escaped strings suitable for inclusion in R code, while the cat function can output those same strings without the escaping.

Thanks for your answer,

I am familiar with the escape strings, but I was looking for a way to 
convert copied path from windows:

working:

y=readline()
# paste f.e c:\foo1\foo2
y
[1] "c:\\foo1\\foo2"


but I was looking for

y=foo("c:\foo1\foo2").
because it is annoying to change all \ to \\ or to /

Regards Knut

______________________________________________
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.



More information about the R-help mailing list