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

From: cstrato <cstrato_at_aon.at>
Date: Tue, 30 Dec 2008 00:33:06 +0100

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
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 29 Dec 2008 - 23:35:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 30 Dec 2008 - 00:31:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive