I'd like to save an R function to disk such that when the enviroment is cleared, I can load() the function and restore both the function itself, as well as any dependencies needed to execute the function. Currently, I can load the function itself, but none of the functions dependencies are restored, so invoking the function fails. Looking for either a package or guidance on how to implement this in R/Rcpp
In other words, looking for an R version of How to pickle a python function with its dependencies?
E.g
testDep=5
testFn = function() {
return(2+testDep)
}
save(testFn, '/tmp/testfn.Rdata')
# --- Clear the env ---
load('/tmp/testfn.Rdata')
testFn()