[R] Transforming a string into a command

Michael Kao mkao006rmail at gmail.com
Sun Nov 27 11:20:15 CET 2011


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.



More information about the R-help mailing list