Re: [R] Lost backslashes in parse()

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

From: Prof Brian Ripley (ripley@stats.ox.ac.uk)
Date: Fri 02 Nov 2001 - 19:24:41 EST


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

On Thu, 1 Nov 2001, David Brahm wrote:

> I'm comparing R-1.3.0 on Solaris 2.6 to R-1.3.1 on WindowsNT. The following
> 5-line script returns TRUE on Unix but FALSE on NT:
>
> fnam <- tempfile()
> file.create(fnam)
> txt <- paste("file.exists(\"", fnam, "\")", sep="")
> expr <- parse(text=txt)
> eval(expr)
>
> The issue seems to be that backslashes get lost in the parsing. A workaround
> is to change the 3rd line to the rather ugly:
> txt <- paste("file.exists(\"", gsub("\\\\","\\\\\\\\",fnam), "\")", sep="")
>
> Do you think this is something parse() should handle better? If not, would it
> be preferable for tempfile() to return a forward-slash filename on NT? How

No! It should be a name that Windows utilities can make use of, as it is
often used in conjunction with system or shell. If you want a
forward-slash version, that is easy to do in R (and you will see examples
throughout the code).

> else could you make this script return TRUE on NT? Thanks!

It seems to me that you just want file.exists(fam).

-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


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

This archive was generated by hypermail 2.1.3 : Thu 17 Jan 2002 - 11:10:08 EST