On 14-02-01 11:40 AM, Hai Qian wrote:
I know using eval is not optimal and maybe bad, but how to avoid using eval in the following examplefunc1 <- function(dat, eval.this) { eval(parse(text = paste0("with(dat, ", eval.this, ")"))) } dat <- data.frame(x = 1:2, y = 2:3) func1(dat, "x*2+y") func1(dat, "sin(x)*cos(y)") Here eval.this is a string that contains whatever the user wants to evaluate. I wonder whether there is a neat way to avoid using eval in this case? So far I have not figured out a way to do this.
You're asking how to parse some text and evaluate it without using eval. Sounds impossible to me.
Duncan Murdoch ______________________________________________ [email protected] 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.

