From ripley at stats.ox.ac.uk  Thu Jan  8 13:14:22 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Thu Jan  8 13:12:55 2004
Subject: [Rd] S3, S4, namespace
In-Reply-To: <8CBAA121CEB4D5118CB200508BB2BBEF05BF73F4@xmx8lonib.lonib.commerzbank.com>
Message-ID: <Pine.LNX.4.44.0401081151420.14344-100000@gannet.stats>

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


[Rd] S3, S4, namespace
Prof Brian Ripley