[Rd] S3, S4, namespace

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jan 8 13:14:22 MET 2004


On Thu, 8 Jan 2004, Heywood, Giles wrote:

> I have encountered an issue which I have been unable to resolve, involving
> an S3 generic (print) being declared S4 generic in a package, and the method

I believe you should not be doing that.  The S4 generic for displaying
objects is show() and not print().  This matters because auto-printing
will use show() rather than print().

> being exported.  This all works fine - the problem occurs when I try to
> import the method to another package.


The other thing I noticed is that you have `import(methods)'.  That is
dangerous, as loading the methods namespace without attaching the package
is known to have problems.  (Take a look at how package mle does this.)
One reason it is dangerous is the following:

R_DEFAULT_PACKAGES=NULL R
> loadedNamespaces()
[1] "base"
> .isMethodsDispatchOn()
[1] FALSE
> loadNamespace("methods")
<environment: namespace:methods>
> .isMethodsDispatchOn()
[1] TRUE
> loadedNamespaces()
[1] "base"    "methods"
> library(MASS)
> detach("package:MASS")
[1] TRUE
> .isMethodsDispatchOn()
[1] FALSE

so if you only load the methods namespace, any call to detach() switches 
off methods dispatch!   That is not the only problem which has been noted.

-- 
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-devel mailing list