From pgilbert902 at gmail.com  Fri Jan  9 22:41:03 2015
From: pgilbert902 at gmail.com (Paul Gilbert)
Date: Fri, 09 Jan 2015 16:41:03 -0500
Subject: [Rd] unloadNamespace
In-Reply-To: <CAFOpNVFdHc3GY7rAS+QiW952MCLUF3x1ofsnE-4NhhyjcU1n9w@mail.gmail.com>
References: <54AEA614.1050803@gmail.com>
	<CAFOpNVFdHc3GY7rAS+QiW952MCLUF3x1ofsnE-4NhhyjcU1n9w@mail.gmail.com>
Message-ID: <54B04AEF.2050002@gmail.com>

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>
>
>



[Rd] unloadNamespace
Paul Gilbert