Skip to content

'load' does not properly add 'show' methods for classes extending 'list'

3 messages · Martin Morgan, Brian Ripley, Robert Gentleman

#
The GeneSetCollection class in the Bioconductor package GSEABase
extends 'list'
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
GeneSetCollection
  names: NA (1 total)
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.
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
#
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:

            

  
    
#
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
   Robert
Prof Brian Ripley wrote: