In Matlab or Octave I can evaluate (evalf) the content of a string. In R I have looked around in the docs, but have not found a way to do something equivalent (which is possible, I think). Can anybody give me a pointer? ============================================================================Thomas Hoffmann, Institut fuer Halbleiter- und Mikrosystemtechnik, TU Dresden E-mail: hoffmann at ehmgs2.et.tu-dresden.de -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Date: Wed, 11 Oct 2000 12:57:16 +0200 (METDST) > From: Thomas Hoffmann <hoffmann at ehmgs2.et.tu-dresden.de> > > In Matlab or Octave I can evaluate (evalf) the content of > a string. In R I have looked around in the docs, but have not > found a way to do something equivalent (which is possible, I think). > > Can anybody give me a pointer?eval(parse(text="ls()")) say, is probably the simplest way. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Hoffmann <hoffmann at ehmgs2.et.tu-dresden.de> writes:> In Matlab or Octave I can evaluate (evalf) the content of > a string. In R I have looked around in the docs, but have not > found a way to do something equivalent (which is possible, I think). > > Can anybody give me a pointer?> eval(parse(text="2+2"))[1] 4 Also check out substitute(), as.name() et al. for other methods of manipulating expressions and function calls -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 11 Oct 2000, Thomas Hoffmann wrote:> In Matlab or Octave I can evaluate (evalf) the content of > a string. In R I have looked around in the docs, but have not > found a way to do something equivalent (which is possible, I think). > > Can anybody give me a pointer? >May be your looking for somethig like:> example <- seq(0,5) > string <- "example" > as.name(string)example> eval(as.name(string))[1] 0 1 2 3 4 5 Hope this helps jan ----------------------------------- Jan Goebel (mailto:jgoebel at diw.de) DIW German Institute for Economic Research SOEP K?nigin-Luise-Str. 5 D-14195 Berlin Germany phone: 49 30 89789-377 ----------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Hoffmann <hoffmann at ehmgs2.et.tu-dresden.de> writes:>In Matlab or Octave I can evaluate (evalf) the content of >a string. In R I have looked around in the docs, but have not >found a way to do something equivalent (which is possible, I think). > >Can anybody give me a pointer? >Use the eval(parse()) pairing: String2Eval <- "A valid R statement" eval(parse(text = String2Eval)) Hope that does the trick. -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>> Can anybody give me a pointer?> eval(parse(text="2+2")) >[1] 4>Also check out substitute(), as.name() et al. for other methods of >manipulating expressions and function callsYou should also consider do.call() if the string is actually the name of a function. Paul Gilbert -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._