Re: [Rd] 'load' does not properly add 'show' methods for classes extending 'list'

From: Robert Gentleman <>
Date: Tue, 25 Sep 2007 09:18:55 -0700

I think that it would be best then, not to load the package, as loading it in this way, means that it is almost impossible to get the methods registered correctly. That does seem to be a bug, or at least a major inconvenience. And one might wonder at the purpose of attaching if not to make methods available.

That said the documentation, indeed does not state that anything good will happen. It also does not state that something bad will happen either.

best wishes


Prof Brian Ripley wrote:

> I am not sure why you expected this to work: I did not expect it to and 
> could not find relevant documentation to suggest it should.
> Loading an object created from a non-attached package does not in general 
> attach that package and make the methods for the class of 'x' available. 
> We have talked about attaching the package defining the class when an S4 
> object is loaded, and that is probably possible now S4 objects can be 
> unambiguously distinguished (although I still worry about multiple 
> packages with the same generic and their order on the search path).
> In your example there is no specific 'show' method on the search path when 
> 'show' is called via autoprinting in the second session, so 'showDefault' 
> is called.  Package GSEABase gets attached as an (undocumented) side 
> effect of calling 'getClassDef' from 'showDefault'.  I can see no 
> documentation (and in particular not in ?showDefault) that 'showDefault' 
> is supposed to attach the package defining the class and re-dispatch to a 
> 'show' method that package contains.  Since attaching packages behind the 
> user's back can have nasty side effects (the order of the search path does 
> mattter), I think the pros and cons need careful consideration: a warning 
> along the lines of
>    'object 'x' is of class "GeneSetCollection" from package 'GSEABase'
>    which is not on the search path
> might be more appropriate.  Things would potentially be a lot smoother if 
> namespaces could be assumed, as loading a namespace has few side effects 
> (and if loading a namespace registered methods for visible S4 generics 
> smoothly).
> Until I see documentation otherwise, I will continue to assume that I do 
> need to attach the class-defining package(s) for things to work correctly.
> On Mon, 24 Sep 2007, Martin Morgan wrote:

>> The GeneSetCollection class in the Bioconductor package GSEABase
>> extends 'list'
>>> library(GSEABase)
>>> showClass("GeneSetCollection")
>> Slots:
>> Name: .Data
>> Class: list
>> Extends:
>> Class "list", from data part
>> Class "vector", by class "list", distance 2
>> Class "AssayData", by class "list", distance 2
>> If I create an instance of this class and serialize it
>>> x <- GeneSetCollection(GeneSet("X"))
>>> x
>> GeneSetCollection
>> names: NA (1 total)
>>> save(x, file="/tmp/x.rda")
>> and then start a new R session and load the data object (without first
>> library(GSEABase)), the 'show' method is not added to the appropriate
>> method table.
>>> load("/tmp/x.Rda")
>>> x
>> Loading required package: GSEABase
>> Loading required package: Biobase
>> Loading required package: tools
>> Welcome to Bioconductor
>> Vignettes contain introductory material. To view, type
>> 'openVignette()'. To cite Bioconductor, see
>> 'citation("Biobase")' and for packages 'citation(pkgname)'.
>> Loading required package: AnnotationDbi
>> Loading required package: DBI
>> Loading required package: RSQLite
>> An object of class "GeneSetCollection"
>> [[1]]
>> setName: NA
>> geneIds: X (total: 1)
>> geneIdType: Null
>> collectionType: Null
>> details: use 'details(object)'
>> Actually, the behavior is more complicate than appears; in a new R
>> session after loading /tmp/x.Rda, if I immediately do x[[1]] I get the
>> show,GeneSetCollection-method but not show,GeneSet-method.
>> Sorry for the somewhat obscure example.
>> Martin
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024

______________________________________________ mailing list
Received on Tue 25 Sep 2007 - 16:27:03 GMT

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 Tue 25 Sep 2007 - 20:42:23 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.