Is this a bug ?> foo <- function(a, ...)+ { + tl <- substitute(list(a=a)) + + ## the foll two should give the same results + ## according to defaults for eval + + print(eval(tl )) + print(eval(tl, parent.frame())) + }> > > foo1 <- function(...)+ { + foo(...) + }> > test <- function(a = 6)+ { + foo1(a = a) + }> > test(10)$a [1] 10 Error in eval(expr, envir, enclos) : Object "a" not found> > str(eval)function (expr, envir = parent.frame(), enclos = if (is.list(envir) || is.pairlist(envir)) parent.frame())>I'm having similar problems with eval(expr, data, parent.frame()) # doesn't work and eval(expr, data) # works where data is a data frame. Deepayan -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Deepayan Sarkar <deepayan@stat.wisc.edu> writes:> Is this a bug ? > > > > foo <- function(a, ...) > + { > + tl <- substitute(list(a=a)) > + > + ## the foll two should give the same results > + ## according to defaults for eval > + > + print(eval(tl )) > + print(eval(tl, parent.frame())) > + }Nope. This is not a bug, just confusing. The thing to note is that default expressions are evaluated in the frame of the called function. I.e. the parent.frame() referred to as the default for envir in eval() is the caller of eval, whereas in eval(expr, parent.frame()) the parent.frame() is evaluated in the callers frame, giving you the grandparent of the eval call. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Reasonably Related Threads
- eval functions... (PR#668)
- Error in eval(expr, envir, enclos) : object 'Rayos' not found???
- predict(lm(etc.), some_data) -> "numeric envir arg not of length one " ???
- Error in eval(expr, envir, enclos)
- sys.source() does not provide the parsing info to eval()