Skip to content
Prev 307608 / 398506 Next

get: problem with environments

On Thu, Oct 11, 2012 at 11:18 AM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:

            
I don't see how the terminal version is getting 5 and 6 rather than 1
and 2, but my testfun2() lets the OP do what he was originally trying
to do.

The difference between testfun() and print(testfun()) (ie, 1 vs 2, or
5 vs 6) is because of lazy evaluation: in print(testfun()), testfun()
is called from inside print() when it needs the value to do method
dispatch.

I can't reproduce the value of 5, so I can't help much. For anyone
wanting to experiment further, it would probably be simpler to use

testfun<-function() sys.nframe()

rather than looking at whether a variable is found or not.  I can't
see how testfun() typed at the global command prompt can return
anything other than 1, but maybe something is getting in between the
console and the evaluator.  For example:
[1] 1
[1] 2
[1] "[1] 6"

I don't see why a pure console program should do this on Linux, though.

   -thomas