I want a function to evaluate one argument in the environment of a data.frame supplied as another argument. "attach" works for this, but "with" does not. Is there a way to make "with" work? I'd rather not attach the data.frame.
With the following two functions "eval.w.attach" works but "eval.w.with" fails: dat <- data.frame(a=1:2) eval.w.attach <- function(x, dat){ attach(dat) X <- x detach() X } eval.w.with <- function(x, dat){ with(dat, x) } eval.w.attach(a/2, dat) # returns c(.5, 1) eval.w.with(a/2, dat) # Error ... 'a' not found Thanks, Spencer Graves [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.