I would like to make a string executable, e.g, s<- "ln(a+b)" a<-1 b<-2 ???? execute string s to obtain ln(a+b) ???? How can I make it? Ciao fron Rome Vittorio
This is one way to do it. a = 1 b = 2 c = parse(text = "log(a + b)") eval(c) Hope this helps. Cheers, On 27/11/2011 11:16 a.m., Victor wrote:> I would like to make a string executable, e.g, > > s<- "ln(a+b)" > a<-1 > b<-2 > > ???? execute string s to obtain ln(a+b) ???? > > How can I make it? > > Ciao fron Rome > Vittorio > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
?eval s<- expression(log(a+b)) a<-1 b<-2 eval(s) Andrija On Sun, Nov 27, 2011 at 11:16 AM, Victor <vdemart@gmail.com> wrote:> I would like to make a string executable, e.g, > > s<- "ln(a+b)" > a<-1 > b<-2 > > ???? execute string s to obtain ln(a+b) ???? > > How can I make it? > > Ciao fron Rome > Vittorio > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]