my understanding of `eval' behaviour is obviously incomplete. my question: usually `eval(expr)' and `eval(expr, envir=parent.frame())' should be identical. why does the last `eval' (yielding `r3') in this code _not_ evaluate in the local environment of function `f' but rather in the global environment (if `f' is called from there)?
#---------------------------------------------------------- f <- function () { a <- 1 x <- 1 model <- y ~ a * x fitfunc <- deriv(model[[3]], c("a"), c("a", "x")) call.fitfunc <- c(list(fitfunc), as.name("a"), as.name("x")) call.fitfunc <- as.call(call.fitfunc) curenv <- environment() cat(" eval(call.fitfunc)\n") r1 = eval(call.fitfunc) str(r1) cat(" eval(call.fitfunc, envir = curenv)\n") r2 = eval(call.fitfunc, envir = curenv) str(r2) cat(" eval(call.fitfunc, envir = parent.frame())\n") r3 = eval(call.fitfunc, envir = parent.frame()) str(r3) } #---------------------------------------------------------- `args(eval)' yields: "function (expr, envir = parent.frame(), enclos = if (is.list(envir) || is.pairlist(envir)) parent.frame() else baseenv())" and the manpage says the same: the default value of `envir' is `parent.frame()'. so I would expect (lazy evaluation) that providing the default argument explicitely should'nt alter the behaviour. where is my error? regards, joerg ______________________________________________ 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.