r - eval.parent using incorrect environment -
in r, noticed odd behavior regarding eval.parent , environment searches when evaluating variable names. following example:
> f = function() {i = 1; g()} > g = function() {eval.parent(substitute(i))} > f() [1] 1 this works expected. expression i evaluated in environment called g, body of f, , 1 result.
however, if define i in body of g well, value used instead despite expression being evaluated in parent frame.
> g = function() {i = 2; eval.parent(substitute(i))} > f() [1] 2 why result 2 in case? definition of i = 2 should ignored eval.parent because expression evaluated in parent frame. having examined environments more closely, call eval eval.parent passed environment corresponding frame of f checked sys.frames.
Comments
Post a Comment