Re: [R] converting character strings to eval

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.ac.be>
Date: Tue 20 Jul 2004 - 00:49:25 EST

Hi Wayne,

what you need is,

eval(parse(text=str))

I hope this helps.

Best,
Dimitris



Dimitris Rizopoulos
Doctoral Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


>
> 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))
>
> But it doesn't seem to work. I am aware of the call command, but
for
> reasons I won't go into I would prefer not to use it.
>
> Any help would be great.
>
> Regards,
> Wayne
>
>
>
>
>
> KSS Ltd
> Seventh Floor St James's Buildings 79 Oxford Street Manchester
M1 6SS England
> Company Registration Number 2800886
> Tel: +44 (0) 161 228 0040 Fax: +44 (0) 161 236 6305
> mailto:kssg_at_kssg.com http://www.kssg.com
>
>
> The information in this Internet email is confidential and
m...{{dropped}}
>
> ______________________________________________
> 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



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:09:23 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:05 EST