Seb

That thread and the resources in Biobase assumes that you have a class
that extends "Versioned".  Doing so will help you in the long run by
providing you with updateObject (at the cost of some complexity).
However, it does not really help you if the existing class does not
extend Versioned.

In general, adding a new slot should not break any existing code, but
you may find users who have old objects lying around that they cannot
use with the new functionality (I assume you are adding slots to
provide new functionality).

Kasper

On Tue, Sep 7, 2010 at 7:39 PM, Sebastian P. Luque <splu...@gmail.com> wrote:
> Hi,
>
> Is there a better approach to adding new slots to an S4 class without
> breaking code that accesses older objects of that class than the
> Bioconductor reference in the thread below?  Thanks.
>
> Cheers,
> Seb
>
>
>
> On Mon, 29 Dec 2008 22:53:50 +0000,
> Wolfgang Huber <hu...@ebi.ac.uk> 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@r-project.org
>>> mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
> --
> Seb
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to