Hello together i want to execute different commands that are saved in strings (eg: "d <- 4+7" and some more complicated things). How can i execute/evaluate them. I know i could save them to a temp-file a read this with source. But is there a way without a file in the middle? I know also the 'assign' command but I think it would only the simply cases. thanks and gruess joerg -- Joerg Maeder .:|:||:..:.||.:: maeder at atmos.umnw.ethz.ch Tel: +41 1 633 36 25 .:|:||:..:.||.:: http://www.iac.ethz.ch/staff/maeder PhD student at INSTITUTE FOR ATMOSPHERIC AND CLIMATE SCIENCE (IACETH) ETH Z?RICH Switzerland -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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, 26 Jun 2002, Joerg Maeder wrote:> i want to execute different commands that are saved in strings (eg: "d > <- 4+7" and some more complicated things). How can i execute/evaluate > them. I know i could save them to a temp-file a read this with source. > But is there a way without a file in the middle? > I know also the 'assign' command but I think it would only the simply > cases.eval(parse(text=string)) -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Joerg Maeder wrote:> > Hello together > > i want to execute different commands that are saved in strings (eg: "d > <- 4+7" and some more complicated things). How can i execute/evaluate > them. I know i could save them to a temp-file a read this with source. > But is there a way without a file in the middle? > I know also the 'assign' command but I think it would only the simply > cases.eval(parse(text = "d <- 4 + 7")) Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Joerg" == Joerg Maeder <maeder at atmos.umnw.ethz.ch> writes:Joerg> i want to execute different commands that are saved Joerg> in strings (eg: "d <- 4+7" and some more complicated Joerg> things). How can i execute/evaluate them. I know i Joerg> could save them to a temp-file a read this with Joerg> source. But is there a way without a file in the Joerg> middle? I know also the 'assign' command but I think Joerg> it would only the simply cases. source() builds on parse() and eval() which you need here. parse() : character --> expression eval () : expressaion --> [evaluated result] E.g., eval(parse(text = "print(d <- 4 + 7)"))> [1] 11Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
eval(parse(text="d<-4+7")) might do the trick. parse turns the text into an expression then eval evaluates it. Cheers, mike. > -----Original Message----- > From: owner-r-help at stat.math.ethz.ch > [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of Joerg Maeder > Sent: 26 June 2002 10:06 > To: R Help > Subject: [R] evaluate a string > > > Hello together > > i want to execute different commands that are saved in > strings (eg: "d > <- 4+7" and some more complicated things). How can i execute/evaluate > them. I know i could save them to a temp-file a read this > with source. > But is there a way without a file in the middle? > I know also the 'assign' command but I think it would only the simply > cases. > > thanks and gruess > > joerg > > -- > Joerg Maeder .:|:||:..:.||.:: maeder at atmos.umnw.ethz.ch > Tel: +41 1 633 36 25 .:|:||:..:.||.:: > http://www.iac.ethz.ch/staff/maeder > PhD student at INSTITUTE FOR ATMOSPHERIC AND CLIMATE SCIENCE (IACETH) > ETH Z?RICH Switzerland > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > .-.-.-.-.-.-.-.-.- > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._