[R] evaluate a string variable

Bill.Venables at csiro.au Bill.Venables at csiro.au
Wed Jun 30 08:04:08 CEST 2010


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.



More information about the R-help mailing list