[R] \ escape sequence and windows path

Bert Gunter gunter.berton at gene.com
Tue May 20 17:32:35 CEST 2014


On Tue, May 20, 2014 at 7:54 AM, Knut Krueger <rh at knut-krueger.de> wrote:
> 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:

Well, if I understand you correctly, your response appear to belie
that claim.  "\" ,the **single** backslash character, is **shown** as
2 backslash characters at the console,"\\" by print() (which is called
silently) , and is **shown** as a single backslash character by cat().
viz.

> paste("a","b",sep="\\") ## "\\" is the escaped single backslash
[1] "a\\b"
> cat(paste("a","b",sep="\\"))
a\b

Does this help clarify? Or have i misunderstood you?

Cheers,
Bert

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