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

Seb spluque at gmail.com
Wed Sep 8 17:36:55 CEST 2010


On Tue, 7 Sep 2010 20:41:14 -0400,
Kasper Daniel Hansen <kasperdanielhansen at gmail.com> wrote:

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

Thanks Kasper, indeed the class I'm working with doesn't have anything
to do with Biobase, and having it extend "Versioned" along with the
package dependencies only for this purpose seems overkill in my case.
But perhaps one can implement a similar approach internally in the
package without having to add a new dependency.


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

Yes, the new slot adds new functionality and I also thought that adding
a slot should not affect existing code.  However, an error message
during 'R CMD check' came up to the effect that an object did not have
the new slot.  Unfortunately, I didn't save more details nor
investigated this error any further, but it got me doubting whether
adding the slot would break existing code and access to objects of the
older class.  The object is under data/, although now I'm considering
removing it and creating it in an example, which might be cleaner.


-- 
Seb



More information about the R-devel mailing list