[Rd] unloadNamespace

Paul Gilbert pgilbert902 at gmail.com
Fri Jan 9 22:41:03 CET 2015


Thanks Winston. That seems like a workaround that might be usefully 
included into unloadNamespace.

Paul

On 15-01-09 12:09 PM, Winston Chang wrote:
> It's probably because the first thing that unloadNamespace does is this:
>     ns <- asNamespace(ns, base.OK = FALSE)
>
> If you call asNamespace("tseries"), it calls getNamespace("tseries"),
> which has the side effect of loading that package (and its dependencies).
>
> One way to work around this is to check loadedNamespaces() before you
> try to unload a package.
>
> -Winston
>
> On Thu, Jan 8, 2015 at 9:45 AM, Paul Gilbert <pgilbert902 at gmail.com
> <mailto:pgilbert902 at gmail.com>> wrote:
>
>     In the documentation the closed thing I see to an explanation of
>     this is that ?detach says "Unloading some namespaces has undesirable
>     side effects"
>
>     Can anyone explain why unloading tseries will load zoo? I don't
>     think this behavior is specific to tseries, it's just an example. I
>     realize one would not usually unload something that is not loaded,
>     but I would expect it to do nothing or give an error. I only
>     discovered this when trying to clean up to debug another problem.
>
>     R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
>     and
>     R Under development (unstable) (2015-01-02 r67308) -- "Unsuffered
>     Consequences"
>     ...
>     Type 'q()' to quit R.
>
>      > loadedNamespaces()
>     [1] "base"      "datasets"  "graphics"  "grDevices" "methods"   "stats"
>     [7] "utils"
>      > unloadNamespace("tseries") # loads zoo ?
>      > loadedNamespaces()
>       [1] "base"      "datasets"  "graphics"  "grDevices" "grid" "lattice"
>       [7] "methods"   "quadprog"  "stats"     "utils"     "zoo"
>      >
>
>     Somewhat related, is there an easy way to get back to a "clean"
>     state for loaded and attached things, as if R had just been started?
>     I'm trying to do this in a vignette so it is not easy to stop and
>     restart R.
>
>     Paul
>
>     ________________________________________________
>     R-devel at r-project.org <mailto:R-devel at r-project.org> mailing list
>     https://stat.ethz.ch/mailman/__listinfo/r-devel
>     <https://stat.ethz.ch/mailman/listinfo/r-devel>
>
>



More information about the R-devel mailing list