Re: [Rd] function remains loaded in the search space after detaching the package

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 24 Feb 2012 12:08:13 +0000

On 24/02/2012 11:20, Martin Maechler wrote:
>>>>>> Joris Meys<jorismeys@gmail.com>
>>>>>> on Fri, 24 Feb 2012 11:24:35 +0100 writes:
>
> > I ran into some very irritating behaviour I don't
> > understand. Let me illustrate with the package gdata()
> > and the function print.object_size() :
>
> >> print(object.size(iris),units='Kb')
> > 6.3 Kb
> >> getAnywhere(print.object_size)
> > A single object matching ‘print.object_size’ was found It
> > was found in the following places registered S3 method for
> > print from namespace utils namespace:utils with value ...
>
> > All is well. So now I load gdata
>
> >> require(gdata)
> > Loading required package: gdata ... The following
> > object(s) are masked from ‘package:utils’:
>
> > object.size
>
> > OK, this is what I would expect:
>
> >> print(object.size(iris),units='Kb')
> > [1] 6424
> >> getAnywhere(print.object_size)
> > 2 differing objects matching ‘print.object_size’ were
> > found in the following places registered S3 method for
> > print from namespace utils namespace:gdata namespace:utils
> > Use [] to view one of them
>
> > Now I detach gdata again
>
> >> detach(package:gdata)
>
> > But the function print.object_size is still the default
> > for object_size objects!
>
> >> print(object.size(iris),units='Kb')
> > [1] 6424
>
> > And it can still be found as well:
>
> >> getAnywhere(print.object_size)
> > 2 differing objects matching ‘print.object_size’ were
> > found in the following places registered S3 method for
> > print from namespace utils namespace:gdata namespace:utils
> > Use [] to view one of them
>
> > Am I missing something?
>
> Yes: the argument 'unload' of detach().
>
> In general: Now that every package has a namespace,
> you (and others) should learn the difference between
> attaching and loading - and hence detach()ing and unloading
> a package with its namespace.
>
> ?detach
> ?library
>
> etc should give a good start.

A very good point, but actually there is more to this one. 'gdata' registers an S3 method which overwrites the one from utils. Unloading a namespace does not unregister its methods (and registration has no stack, so there is no way R knows what was there before).

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 24 Feb 2012 - 12:13:23 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 24 Feb 2012 - 13:40:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive