[R] The default argument 'envir' of eval()
bluesky315 at gmail.com
bluesky315 at gmail.com
Tue Feb 9 18:18:08 CET 2010
In ?eval, it says
... If ‘envir’ is not
specified, then the default is ‘parent.frame()’ (the environment
where the call to ‘eval’ was made).
I tried the following example with "eval(expr)" and "eval(expr,
parent.frame())" in f(). The results are different, which are not
consistent with the help. Could somebody let know whether I
misunderstand the help? Or there is something with the help?
> expr=expression(print(paste('x =', x)))
> x=0
> f=function() {
+ x=2
+ eval(expr)
+ eval(expr, parent.frame())
+ eval(expr, parent.frame(2))
+ eval(expr, parent.frame(3))
+ }
> g=function() {
+ x=1
+ f()
+ }
>
> g()
[1] "x = 2"
[1] "x = 1"
[1] "x = 0"
[1] "x = 0"
More information about the R-help
mailing list