limma MArrayLM subclass question
1
0
Entering edit mode
@gordon-smyth
Last seen 6 hours ago
WEHI, Melbourne, Australia
Hi Cyrus, This is a bit laconic for me. Can you give explicit reproducible code which leads to an error, and send back to list? I assume you wouldn't be trying to do something as advanced as creating a new sub-class without reading the help for as() and setAs() etc, but the usage you describe for as() certainly does not appear to match the function definition. Have you successfully experimented with a toy example of a class and subclass and got everything working? If not, R-help would be a better place for questions about S4. Regards Gordon >Dear bioc-devel, > >I'd like to subclass MArrayLM (I think), but I'm having some trouble: > >setClass("myMArrayLM", "MArrayLM") >assign("[.myMArrayLM", function(object, i, j, ...) >{ "[.MArrayLM"(object, i, j, ...) }); > >and then I thought I could just do this (given def, an MArrayLM object) > >as("myArrayLM", def); > >But when I try that I get the following error message: > > > as("myArrayLM", def); >Error in methodsPackageMetaName("C", name) : > 'The name of the object (e.g,. a class or generic function) to >find in the meta-data' must be a single string (got an object of >class "matrix") >In addition: Warning message: >the condition has length > 1 and only the first element will be used >in: if is.na(i)) { > > > >Has anyone successfully subclassed MArrayLM? Is this something I just >shouldn't be doing? It seems natural to want to store additional data >in an MArrayLM and get the proper subsetting behavior, piggybacking >on MArrayLM's existing behavior. > >Also, is this the right place for limma questions? It doesn't have >its own mailing list yet, does it? > >Thanks, > >Cyrus Harmon
limma limma • 1.4k views
ADD COMMENT
0
Entering edit mode
Cyrus Harmon ▴ 140
@cyrus-harmon-1173
Last seen 9.7 years ago
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: > setClass("moose", representation(antler="character")) [1] "moose" > setClass("oldMoose", representation("moose",age="numeric")) [1] "oldMoose" > m1 <- new("moose", antler="bogus") > m1 An object of class "moose" Slot "antler": [1] "bogus" > m2 <- as(m1, "oldMoose") > m2 An object of class "oldMoose" Slot "age": numeric(0) Slot "antler": [1] "bogus" > 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" attr(,"package") [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 bandwidth. Thanks again, Cyrus On Sep 15, 2005, at 10:53 PM, Gordon Smyth wrote: > Hi Cyrus, > > This is a bit laconic for me. Can you give explicit reproducible > code which leads to an error, and send back to list? > > I assume you wouldn't be trying to do something as advanced as > creating a new sub-class without reading the help for as() and setAs > () etc, but the usage you describe for as() certainly does not > appear to match the function definition. Have you successfully > experimented with a toy example of a class and subclass and got > everything working? If not, R-help would be a better place for > questions about S4. > > Regards > Gordon > > >> Dear bioc-devel, >> >> I'd like to subclass MArrayLM (I think), but I'm having some trouble: >> >> setClass("myMArrayLM", "MArrayLM") >> assign("[.myMArrayLM", function(object, i, j, ...) >> { "[.MArrayLM"(object, i, j, ...) }); >> >> and then I thought I could just do this (given def, an MArrayLM >> object) >> >> as("myArrayLM", def); >> >> But when I try that I get the following error message: >> >> > as("myArrayLM", def); >> Error in methodsPackageMetaName("C", name) : >> 'The name of the object (e.g,. a class or generic function) to >> find in the meta-data' must be a single string (got an object of >> class "matrix") >> In addition: Warning message: >> the condition has length > 1 and only the first element will be used >> in: if is.na(i)) { >> > >> >> Has anyone successfully subclassed MArrayLM? Is this something I just >> shouldn't be doing? It seems natural to want to store additional data >> in an MArrayLM and get the proper subsetting behavior, piggybacking >> on MArrayLM's existing behavior. >> >> Also, is this the right place for limma questions? It doesn't have >> its own mailing list yet, does it? >> >> Thanks, >> >> Cyrus Harmon >> > > >
ADD COMMENT
0
Entering edit mode
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" >attr(,"package") >[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 >bandwidth. > >Thanks again, > >Cyrus 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? Gordon
ADD REPLY

Login before adding your answer.

Traffic: 947 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6