Correct me if I'm wrong, but it also seems that more generally, everything
works as long as the environment is 'below' .GlobalEnv.  For example,

x = function(){
   y = 4
   function()y
}
yfun = x()
save(yfun,file = "yfun.RData")

load("yfun.RData")
yfun()

This works fine even when there are more inherited environments.  I imagine
this is because in saving yfun, it also saves the environment and any
parent environments until some point?  Is it checking to see if the
environment inherits from .GlobalEnv or something like that?

Jamie Olson



On Wed, Nov 7, 2012 at 7:57 PM, Duncan Murdoch <murdoch.duncan@gmail.com>wrote:

> On 12-11-07 6:20 PM, Jamie Olson wrote:
>
>> Thank you!  This explains the error thrown by getNamespace() for the
>> missing package.
>>
>> So I imagine this will happen for any function's environment?  Do you
>> know if this should happen for S3 objects or just S4?
>>
>
> It should only happen for objects that have an environment associated with
> them.  Functions do, S4 objects do, formulas do, but S3 objects don't
> (unless they happen to contain something that does).
>
> If the environment is globalenv() (the user environment), it's no big
> deal.  It's only when a package namespace is there (as with functions
> exported from a package) that you create the dependency.
>
> Duncan Murdoch
>
>
>>
>> Jamie Olson
>>
>>
>>
>> On Wed, Nov 7, 2012 at 4:10 PM, Duncan Murdoch <murdoch.duncan@gmail.com
>> <mailto:murdoch.duncan@gmail.**com <murdoch.duncan@gmail.com>>> wrote:
>>
>>     On 07/11/2012 12:50 PM, Jamie Olson wrote:
>>
>>         Could someone explain to me what namespaces are loaded/saved
>>         when objects
>>         are saved?
>>
>>
>>     None are loaded or saved when you save the object, but the names of
>>     some are saved.  For example,
>>
>>     library(Hmisc)  # not normally loaded/attached
>>     x <- zoom # copy a function from Hmisc
>>     save(x, file="x.RData")
>>
>>     This will save a copy of a function from Hmisc to the file, but the
>>     function's environment is the Hmisc namespace.  To properly load
>>     that function via
>>
>>     load("x.RData")
>>
>>     R will load the referenced namespace.  You will see it appear in
>>     loadedNamespaces() after the load (assuming you still have Hmisc
>>     available).
>>
>>     I believe this will also happen if you try to load an S4 object;
>>     you'll need to be able to load the namespace of its class.
>>
>>     Duncan Murdoch
>>
>>
>>
>>         Specifically, I'm using this:
>>            save(list = ls(all.names = TRUE, envir = envir), file = name,
>>         envir =
>>         envir)
>>         to save out everything from an environment.
>>
>>         Later, loading it on another machine, I'm surprised to see the
>>         load failing
>>         for being unable to load certain packages.  Could anyone help me
>>         understand
>>         why this happens?
>>         Jamie Olson
>>
>>                  [[alternative HTML version deleted]]
>>
>>         ______________________________**__________________
>>         R-help@r-project.org <mailto:R-help@r-project.org> mailing list
>>         https://stat.ethz.ch/mailman/_**_listinfo/r-help<https://stat.ethz.ch/mailman/__listinfo/r-help>
>>
>>         <https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> >
>>         PLEASE do read the posting guide
>>         http://www.R-project.org/__**posting-guide.html<http://www.R-project.org/__posting-guide.html>
>>
>>         <http://www.R-project.org/**posting-guide.html<http://www.R-project.org/posting-guide.html>
>> >
>>         and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>>
>

	[[alternative HTML version deleted]]


