You need to parse it before you evaluate it.

eval(parse(text = avar)) 

-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jeremiah H. Savage
Sent: Wednesday, 30 June 2010 3:45 PM
To: r-help@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@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@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.

Reply via email to