Skip to content
Back to formatted view

Raw Message

Message-ID: <B239F9695173744188ABD377D1D44CDF370013F6@Exchange>
Date: 2011-08-02T15:06:29Z
From: Samuel Le
Subject: execute r-code stored in a string variable
In-Reply-To: <60F5867E29CEBC45A921E3D9B2B7511609796203E3@SERVER1.dataminds.local>

Yes, you can use:
eval(parse(text=c))

On the other hand I would not recommend to use c as a variable name as it is the name of a very important function in the R language to aggregate data.

HTH,
Samuel

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Kim Lilles?e
Sent: 02 August 2011 13:22
To: r-help at R-project.org
Subject: [R] execute r-code stored in a string variable

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]]



__________ Information from ESET NOD32 Antivirus, version of virus signature database 6275 (20110707) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature database 6275 (20110707) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com