[R] pasting "\" into character strings

John Miyamoto jmiyamot at u.washington.edu
Sun Dec 22 09:02:03 CET 2002


Dear R-Help,
   I'm using R version 1.6.0 on a Windows computer.  I am trying to create
a function that, among other things, constructs strings that refer to
Windows files, e.g., I might want to construct a string like
'c:\work\part1.txt'.  I have found that the following does not work.

> paste("c:", "\", "work", "\", "part1.txt", sep="")
Error: syntax error

I'm guessing that R interprets "\" as some kind of special control
character, and that there is some way to show that one wants a literal
interpretation of "\" and not a control interpretation, but I haven't been
able to find an explanation of this issue.  I understand that I must use
'c:\\work\\part1.txt' or 'c:/work/part1.txt' to refer to the file that
Windows knows as 'c:\work\part.txt', but what I'm trying to do is to
write an R function that writes references to Windows files into a text
file, where a different Windows programs will later read these references
in the standard Windows syntax.
   Can someone tell me how to create the character string
'c:\work\part1.txt' from the parts, "c:", "work", an "part1.txt"?

John Miyamoto

--------------------------------------------------------------------
John Miyamoto, Dept. of Psychology, Box 351525
University of Washington, Seattle, WA 98195-1525
Phone 206-543-0805, Fax 206-685-3157, Email jmiyamot at u.washington.edu
Homepage http://faculty.washington.edu/jmiyamot/
--------------------------------------------------------------------




More information about the R-help mailing list