[R] How do I really, I mean really, unload a package?

Kevin Wright kw.stat at gmail.com
Wed Sep 24 22:24:22 CEST 2014


To follow up, my attempt at creating a minimal example went a bit too minimal.

What I _think_ actually happened to me is that I loaded two packages
with identical-named S3 methods for a generic.  Even after unloading
the second package, the S3 methods for that package were still
registered and somehow re-loaded (?) when I tried to print an object
(of the same class) that had been created using the first package.

I found a post by Professor Ripley which seems to confirm something to
the effect that it is not possible to unregister S3 methods:
http://tolstoy.newcastle.edu.au/R/help/06/07/30791.html

In that sense, it appears that it is not possible to completely undo
the loading of a package.

Thanks to Bill Dunlap and Professor Ripley.

Kevin Wright



On Wed, Sep 24, 2014 at 2:16 PM, William Dunlap <wdunlap at tibco.com> wrote:
> Running pkg::func or pkg:::func has the side effect of loading pkg's
> namespace, if it is not already loaded.  Use remove.packages() to
> remove the package from your machine if you want to make its namespace
> unloadable.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Wed, Sep 24, 2014 at 11:56 AM, Kevin Wright <kw.stat at gmail.com> wrote:
>> Sorry if this is well-known, but I can't find an answer or maybe just don't
>> know how to ask Google the right question.  If I run the following code in
>> R (3.1.1), I find that lattice:::xyplot.formula is still available (or
>> maybe just a promise to it ... ???) even though I've used detach and
>> unloadNamespace.  Is there another step I'm missing?
>>
>> require(lattice)
>> head(lattice:::xyplot.formula)
>> detach(package:lattice)
>> search() # No longer on search list
>> loadedNamespaces() # But namespace is still loaded
>> unloadNamespace("lattice")
>> loadedNamespaces() # Namespace not loaded
>> head(lattice:::xyplot.formula)  # It is still accessible
>>
>> Kevin
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.



-- 
Kevin Wright



More information about the R-help mailing list