[R] pasting "\" into character strings
John Miyamoto
jmiyamot at u.washington.edu
Sun Dec 22 12:08:03 CET 2002
On Sun, 22 Dec 2002 ripley at stats.ox.ac.uk wrote:
> Why guess? It's in the R Language definition and in all good books on
> S/R.
>
> `String constants are delimited by a pair of single (') or double (")
> quotes and can contain all other printable characters. Quotes and other
> special characters within strings are specified using escape sequences:'
>
> paste("c:", "work", "part1.txt", sep="\\")
Reply: The problem with this command is that it produces
paste("c:", "work", "part1.txt", sep="\\")
[1] "c:\\work\\part1.txt"
whereas I want "c:\work\part1.txt". Some people have suggested to try
'file.path', but it either doesn't work, or I don't know how to make it
work.
> file.path("c:","work","part1.txt", fsep = "\")
Error: syntax error
> file.path("c:","work","part1.txt", fsep = "\\")
[1] "c:\\work\\part1.txt"
John Miyamoto
More information about the R-help
mailing list