[Rd] 'load' does not properly add 'show' methods for classes extending 'list'
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Sep 25 10:18:09 CEST 2007
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
>
--
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