From winstonchang1 at gmail.com  Fri Jan  9 18:09:46 2015
From: winstonchang1 at gmail.com (Winston Chang)
Date: Fri, 9 Jan 2015 11:09:46 -0600
Subject: [Rd] unloadNamespace
In-Reply-To: <54AEA614.1050803@gmail.com>
References: <54AEA614.1050803@gmail.com>
Message-ID: <CAFOpNVFdHc3GY7rAS+QiW952MCLUF3x1ofsnE-4NhhyjcU1n9w@mail.gmail.com>

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> 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 mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



[Rd] unloadNamespace
Winston Chang