[R] How to pass an object between two independant environment?

Frederic Fournier frederic.bioinfo at gmail.com
Wed Oct 2 16:12:49 CEST 2013

Hello everyone,

I am trying to pass an object cleanly between two independant 
environments, any ideas on how to do that?

I have something like this:

calling.function <- function(my.object) {
... ...
local(source("function_to_which_I_want_to_pass_my_object.Rda", local = 
new.env(parent = .GlobalEnv))) # I can't change this part of the code

The calling function will be part of a package, so I don't want to use 
the global environment (that's the user's space, not a space that should 
be used by the packages). Writing a temp file is unclean for the same 
reason (and using the user's hard-drive is actually worse than using its 
space in R!). The package namespace is locked when the package is 
loaded, so using the package environment is not a perfect option either.

I was wondering, is there a way to create a named environment in R? If 
it was possible to do that, then the calling function could 'assign' to 
the named-environment and the scripted function could 'get' from it and 
the problem would be solved.

Thanks for your help,


More information about the R-help mailing list