[Rd] bug in eval
Peter Dalgaard BSA
p.dalgaard@biostat.ku.dk
20 Jul 2001 00:29:00 +0200
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._