Re: [R] evaluate a string variable

From: <Bill.Venables_at_csiro.au>
Date: Wed, 30 Jun 2010 16:04:08 +1000

You need to parse it before you evaluate it.

eval(parse(text = avar))

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Jeremiah H. Savage Sent: Wednesday, 30 June 2010 3:45 PM
To: r-help_at_r-project.org
Subject: [R] evaluate a string variable

Hello,

I was wondering how to evaluate a string variable in R.

eg.

> avar <- "getwd()"
> eval(avar)

gives:
[1] "getwd()"

but I would like to see:
[1] "/home/myhomedir"

Thanks,
Jeremiah



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.

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. Received on Wed 30 Jun 2010 - 06:06:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Jun 2010 - 06:10:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive