Re: [R] pasting "\" into character strings

About this list Date view Thread view Subject view Author view Attachment view

From: ripley@stats.ox.ac.uk
Date: Sun 22 Dec 2002 - 19:26:26 EST


Message-id: <Pine.LNX.4.31.0212220820010.26654-100000@gannet.stats>

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="\\")

On Sun, 22 Dec 2002, John Miyamoto wrote:

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

c:/work/part1.txt *is* standard Windows syntax, too!

> Can someone tell me how to create the character string
> 'c:\work\part1.txt' from the parts, "c:", "work", an "part1.txt"?

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ R-help@stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jun 2004 - 09:31:59 EST