This has been discussed extensively, on this list as well as elsewhere. I suggest doing a web search, read up on the issue, and post back here only if you have specific questions that are not answered already.
Best, Ista On Sat, Feb 1, 2014 at 11:40 AM, Hai Qian <hq...@gopivotal.com> wrote: > I know using eval is not optimal and maybe bad, but how to avoid using eval > in the following example > > func1 <- 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. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.