From spluque at gmail.com  Wed Sep  8 01:39:54 2010
From: spluque at gmail.com (Sebastian P. Luque)
Date: Tue, 07 Sep 2010 18:39:54 -0500
Subject: [Rd] How to add a slot to S4 class of an existing package?
In-Reply-To: <495954FE.6070401@ebi.ac.uk> (Wolfgang Huber's message of "Mon,
	29 Dec 2008 22:53:50 +0000")
References: <494FECF9.2020301@aon.at> <495954FE.6070401@ebi.ac.uk>
Message-ID: <878w3df7hx.fsf@kolob.sebmags.homelinux.org>

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 <huber at 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 at r-project.org
>> mailing list https://stat.ethz.ch/mailman/listinfo/r-devel


-- 
Seb



[Rd] How to add a slot to S4 class of an existing package?
Sebastian P. Luque