[R] Lost backslashes in parse()

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Nov 2 17:45:30 CET 2001


David Brahm  <a215020 at agate.fmr.com> writes:

> 
> 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!

I suspect what you really want is something like

eval(substitute(save(list=n, file=fn), list(fn=file, n=i)), pos)

I still don't see the problem with the backslashes, though. Yes, stuff
like this *is* needed:

> parse(text="\"\\\"\"")
expression("\"")

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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