I want to save an anonymous function in an object and serialize that object, but that object should not grow huge. It is then necessary that the function's environment hierarchy doesn't contain too much other stuff.
Usecase:
x = 1
large_obj = [huge object that takes lots of memory]
want_to_serialize = function(arg) return(arg + x)
saveRDS(want_to_serialize, "savefile.rds")
want_to_serialize's environment now contains large_obj and the savefile grows large. Instead I would want a function detachEnv(fun, keep, basis):
I want to save an anonymous function in an object and serialize that object, but that object should not grow huge. It is then necessary that the function's environment hierarchy doesn't contain too much other stuff.
Usecase:
want_to_serialize
's environment now containslarge_obj
and the savefile grows large. Instead I would want a functiondetachEnv(fun, keep, basis)
:code for this:
name up for debate