[R] Lost backslashes in parse()

Thomas Lumley tlumley at u.washington.edu
Fri Nov 2 00:26:21 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
> else could you make this script return TRUE on NT?  Thanks!

I don't understand why you are doing the paste and parse step, so I may
not be able to help properly, but it seems to be that

 fnam <- tempfile()

would work. There are also functions to manipulate paths described in
help(file.path) and help(basename)


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