[R] detach
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Jul 12 20:48:10 CEST 2006
Looks like one can do the following. Don't know if it would cause
problems elsewhere. Note that after removing as.Date.numeric
from the S3 Methods Table as.Date.numeric was no longer dispatched.
> as.Date(1)
Error in as.Date.default(1) : do not know how to convert '1' to class "Date"
> library(zoo)
> as.Date(1)
[1] "1970-01-02"
> unloadNamespace("zoo")
<environment: namespace:zoo>
> rm(as.Date.numeric, envir = .__S3MethodsTable__.)
> as.Date(1)
Error in as.Date.default(1) : do not know how to convert '1' to class "Date"
On 7/12/06, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On Wed, 12 Jul 2006, Martyn Plummer wrote:
>
> > My guess is that even though the zoo namespace is unloaded. The S3
> > method as.Date.numeric is still registered, and the name space will be
> > reloaded whenever it is dispatched.
> > > library(zoo)
> > > loadedNamespaces()
> > [1] "base" "graphics" "grDevices" "methods" "stats" "utils"
> > [7] "zoo"
> > > unloadNamespace("zoo")
> > <environment: namespace:zoo>
> > > loadedNamespaces() #Gone
> > [1] "base" "graphics" "grDevices" "methods" "stats" "utils"
> > > as.Date(1)
> > [1] "1970-01-02"
> > > loadedNamespaces() #Back again!
> > [1] "base" "graphics" "grDevices" "methods" "stats" "utils"
> > [7] "zoo"
> >
> > So the question is whether there is a way to unregister an S3 method, so
> > that you can restore the method dispatching behaviour prior to the
> > package being loaded. I don't know the answer, but I'm guessing it's no.
>
> It is no. Namespaces don't work that way: one would have to keep a stack
> of past registered methods to be able to back out a registered method.
>
> --
> 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
>
More information about the R-help
mailing list