I would like to create a function within a package with a NAMESPACE that will save
some variables. The problem is that when load
is called on the .Rdata file it
tries to load the namespace of the package that contained the function that created the .Rdata file, but this package need not be loaded.
This example function is in a package in a namespace :
create.global.function <- function(x, FUN, ...) {
environment(FUN) <- .GlobalEnv
assign(".GLOBAL.FUN", function(x) { FUN(x, ...) }, env=.GlobalEnv)
environment(.GLOBAL.FUN) <- .GlobalEnv
save(list = ls(envir = .GlobalEnv, all.names = TRUE),
file = "/tmp/.Rdata",
envir = .GlobalEnv)
}
The environment(.GLOBAL.FUN) <- .GlobalEnv
calls are not sufficient and attaching gdb to the R process confirms it is serializing a NAMESPACESXP
here with the name of the package namespace and the load
fails because it is unable to load this.
Is it possible to fully strip the namespace out of the .GLOBAL.FUN
before I save
it such that it can be loaded into other R instances without trying to load the namespace?