Skip to content
Prev 20822 / 63421 Next

save() saves extra stuff if object is not evaluated

On Thu, 25 May 2006, Henrik Bengtsson wrote:

            
No, it's exactly that simple.  Serialization follows and writes out
all reachable environments.  Unevaluated promises contain the
environments in which their evaluations are to occur; evaluated ones
have this field set to R_NilValue to eliminate this no longer needed
reference.

There are two environments involved: the calling environment in which
saveCache is called and the callee environment of the call to
saveCache where the body of saveCache is evaluated.  Because of
lexical scope the enclosing environment of the callee environment is
the closure environment of saveCache, which is .GlobalEnv.

The call to saveCache creates a promise for evaluating the default
value for 'source' _in the callee environment_. In the case with y the
callee environment includes a value of y which is a promise
referencing the calling environment (either .GlobalENv or the
environment of the call to main).  In the calls without y the value of
y in the calling environment is the missing value indicator, not a
promise.  So only with y and no eval is there a reference to the
calling environment that serialization then has to write out.

Best,

luke