Re: [R] converting character strings to eval

From: Deepayan Sarkar <deepayan_at_stat.wisc.edu>
Date: Tue 20 Jul 2004 - 00:52:35 EST

On Monday 19 July 2004 09:37, Wayne Jones wrote:
> Hi there fellow R-users,
>
> I'm stuck on this seemingly trivial problem.
>
> All I want to coerce a character string into a command.
>
> For example:
>
> x<-rnorm(20)
> y<-rnorm(20)
> str<-"lm(y~x)"
>
> I want to evaluate the "str" command.
>
> I have tried
>
> eval(as.expression(str))

eval(parse(text = str))

seems to work.

Deepayan



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 20 01:14:14 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:36:49 EST