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
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 stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.