[R] Lost backslashes in parse()
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Nov 2 09:24:41 CET 2001
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 at 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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list