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! -- David Brahm (brahm at alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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() file.create(fnam) file.exists(fnam) would work. There are also functions to manipulate paths described in help(file.path) and help(basename) -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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? HowNo! 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi all, Yesterday I gave this 5-line example of a script that returns TRUE in Unix (R-1.3.0 on Solaris 2.6) but FALSE in NT (R-1.3.1): R> fnam <- tempfile() R> file.create(fnam) R> txt <- paste("file.exists(\"", fnam, "\")", sep="") R> expr <- parse(text=txt) R> eval(expr) Thanks to Thomas Lumley <tlumley at u.washington.edu> and Brian D. Ripley <ripley at stats.ox.ac.uk> for responding. Both asked why lines 3-5 weren't just replaced by the much simpler: R> file.exists(fnam) The short answer is that this was a toy, and in the real situation I need to eval() in a different environment. If nobody else is disturbed by this behavior in parse(), I can easily work around it, so don't worry about it. For anyone masochistic enough to dig further, though, here's a snippet of the real code: R> for (i in obj) { R> file <- file.path(dir, "data", paste(i,"RData",sep=".")) R> expr <- parse(text=paste("save(list=\"",i,"\", file=\"",file,"\")",sep="")) R> eval(expr, pos.to.env(pos)) R> } Since the object named in "i" may exist somewhere besides "pos", I need to eval() the save() command in the environment of position "pos". But in that environment, "i" and "file" don't exist, so I need to build the command ahead of time as a text string [i.e. evalq() won't work]. Again, this all works OK for me except for backslash dropping in NT. Thanks again for listening! -- David Brahm (brahm at alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._