[Rd] How to add a slot to S4 class of an existing package?

cstrato cstrato at aon.at
Tue Dec 30 00:33:06 CET 2008


Dear Wolfgang

Thank you very much for pointing me to this link, in principle this 
would answer my question: Method updateObject() of package Biobase would 
be exactly what I am looking for. However, I have hoped that maybe there 
is also a solution for S4 classes in general.

Somehow I feel that package Biobase has solved a couple of shortcomings 
of S4 classes. People may not agree with me but I think that method 
"updateObject()" should belong to package "methods" so that every S4 
class can profit from it.

Nevertheless, thank you once again, I will have a look at the code of 
package Biobase.

Best regards and Happy New Year
Christian

Wolfgang Huber wrote:
> Dear Christian
>
> this post from Martin Morgan on class versioning in Bioconductor's 
> Biobase package might be relevant:
> https://stat.ethz.ch/pipermail/bioc-devel/2006-May/000545.html
> and also section 6 of this:
> http://www.bioconductor.org/packages/2.4/bioc/vignettes/Biobase/inst/doc/BiobaseDevelopment.pdf 
>
>
>     Best wishes
>     Wolfgang
>
> ----------------------------------------------------
> Wolfgang Huber  EMBL-EBI  http://www.ebi.ac.uk/huber
>
> cstrato wrote:
>> Dear all,
>>
>> Since my package is based on S4 classes, I would like to know how to 
>> add a slot to an existing S4 class without breaking the code of users 
>> of my package.
>>
>> Assume the following S4 class:
>> setClass("MyClass",
>>   representation(name = "character",
>>                  type = "character",
>>                  data = "data.frame"
>>   ),
>>   prototype(name = "",
>>             type = "Default",
>>             data = data.frame(matrix(nr=0,nc=0))
>>   )
>> )#MyClass
>>
>> Assume that a user has created an object:
>>  > myclass <- new("MyClass", name="MyName", type="MyType", data=tmp)
>>  > str(myclass)
>>
>>
>> Now I would like to add another slot "info" to MyClass:
>> setClass("MyClass",
>>   representation(name = "character",
>>                  type = "character",
>>                  data = "data.frame",
>>                  info = "data.frame"
>>   ),
>>   prototype(name = "",
>>             type = "Default",
>>             data = data.frame(matrix(nr=0,nc=0)),
>>             info = data.frame(matrix(nr=0,nc=0))
>>   )
>> )#MyClass
>>
>> Now when the user loads my package with S4 class MyClass containing a 
>> new slot and calls:
>>  > str(myclass)
>> Error in FUN(c("name", "type", "data", "info")[[4L]], ...) :
>>  no slot of name "info" for this object of class "MyClass"
>>  >
>>
>> My question is:
>> Is there any possibility or special trick, which would avoid this 
>> error message?
>>
>> Are there other possibilities to access an additional data.frame from 
>> an existing class?
>>
>> Is there something like an "evolution" of S4 classes, which 
>> distinguishes the different implementations of an S4 class, and 
>> allows the user to keep the object of an old class?
>>
>> Best regards
>> Christian
>> _._._._._._._._._._._._._._._._._._
>> C.h.r.i.s.t.i.a.n   S.t.r.a.t.o.w.a
>> V.i.e.n.n.a           A.u.s.t.r.i.a
>> e.m.a.i.l:        cstrato at aon.at
>> _._._._._._._._._._._._._._._._._._
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



More information about the R-devel mailing list