[R] execute r-code stored in a string variable

Ista Zahn izahn at psych.rochester.edu
Tue Aug 2 16:05:31 CEST 2011


Hi Kim,
You can use

eval(parse(text = c))

Best,
Ista

On Tue, Aug 2, 2011 at 8:22 AM, Kim Lillesøe <kli at dataminds.dk> wrote:
> Dear all
>
> I have a simple R question. How do I execute R-code stored in a variable?
>
> E.g if I have a variable which contains some R-code:
> c = "reg <- lm(sales$sales~sales$price)"
>
> Is it possible to execute c
> E.g like Exec(c)
>
> I hope someone can help.
>
> Thank you
> Kim Lillesře
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list