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 - 22:42:06 EST


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

Oh dear, oh dear, oh dear!

My answer is correct, and it does gives you

c:\work\part1.txt

However, print() (which you have called by auto-printing) escapes the
escape characters. cat() does not, so you get

> x <- paste("c:", "work", "part1.txt", sep="\\")
> x
[1] "c:\\work\\part1.txt"
> cat(x, "\n")
c:\work\part1.txt

On Sun, 22 Dec 2002, John Miyamoto wrote:

> On Sun, 22 Dec 2002 ripley@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
>
>

-- 
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:58 EST