[BioC] limma MArrayLM subclass question

Gordon Smyth smyth at wehi.edu.au
Fri Sep 16 09:24:22 CEST 2005

At 04:39 PM 16/09/2005, Cyrus Harmon wrote:
>Hi Gordon,
>Sorry for the bogus code there. Let me try again. As for reading the
>help pages, yes, certainly. As for getting the usage correct? No,
>you're right, that was wrong. However, the problem that led me to
>writing the email in the first place still seems to exist. Allow me
>to try again.
>First, for the trivial example of a class and subclass to prove to
>myself that I'm not completely inept:


>Second, for the example with MArrayLM that still doesn't seem to work
>for me:
> > setClass("myMArrayLM", representation("MArrayLM"))
>[1] "myMArrayLM"
> > class(def)
>[1] "MArrayLM"
>[1] "limma"
> > as(def,"myMArrayLM");
>Error in names(x) : trying to get slot "contains" from an object of a
>basic class ("NULL") with no slots
>Obviously, this is not a completely reproducible example as def is a
>big object. But I trust that if one were to plug in another MArrayLM
>object, instead of def, one would see the same results.
>If I'm missing something fundamental, my apologies for taking up bioc
>Thanks again,

This error occurs because you are trying to use the default definition of 
'as', but this applies only to the simple case where the subclass is the 
same as the original class but with extra slots. This is not such a case 
because you have defined no extra slots. Consider: how would R know how to 
coerce an MArrayLM object to an myMarrayLM object when you actually haven't 
told it anything about the structure of your class?

You have three choices:

1. Define 'as' explicitly using the setAs() function. There are examples of 
this in the convert package.

2. Define your new class using an explicit slot, for example:

 > library(limma)
 > setClass("myMArrayLM",representation(x="numeric"),contains="MArrayLM")
[1] "myMArrayLM"
 > a <- new("myMArrayLM")
 > as(a,"MArrayLM")
An object of class "MArrayLM"

3. Do you really need to define a new class anyway? What is it specifically 
that you are trying to do? Have you noted that MArrayLM is actually simply 
a list, i.e., it has only the default slot .Data, so that S4 is used only 
to attach a formal class membership. This means that you can add components 
to it freely without defining a new class, in fact that it why it was done 
that way. Would that serve your purpose?


More information about the Bioconductor mailing list