[R] evaluation revisited

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed Jan 28 12:35:03 CET 2009


Wacek Kusnierczyk wrote:
> Gabor Grothendieck wrote:
>   
>> The argument to eval.parent is evaluated before eval.parent
>> ever sees it. 
>>     
>
> really?  eval.parent is just a regular r function, a wrapper for eval
> with envir=parent.frame().  the arguments to eval.parent are passed to
> eval *unevaluated* (as promises), and are only evaluated when eval needs
> them.  

to be strict, the argument n to eval.parent is not further passed to
eval, and is evaluated before eval is called.  the above referred to the
'expr' argument to eval.parent.  one more example:

my.eval.parent = function(expr, n=1) {
    print('foo')
    p = parent.frame(n+1)
    eval(expr, p) }
trace(eval)
my.eval.parent({print('expr'); 1}, {print('n'); 1})
# "foo"
# "n"
# trace eval(expr, p)
# "expr"
# 1


vQ




More information about the R-help mailing list