From p.dalgaard@biostat.ku.dk  Thu Jul 19 23:29:00 2001
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 20 Jul 2001 00:29:00 +0200
Subject: [Rd] bug in eval
In-Reply-To: Deepayan Sarkar's message of "Thu, 19 Jul 2001 15:51:28 -0500 (CDT)"
References: <Pine.LNX.4.21.0107191543030.20317-100000@gstat03.stat.wisc.edu>
Message-ID: <x2elrcbljn.fsf@blueberry.kubism.ku.dk>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] bug in eval
Peter Dalgaard BSA