Skip to content

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

3 messages · Kasper Daniel Hansen, Sébastien Bihorel

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

            

        

  
    
#
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 <spluque at gmail.com> wrote:
#
On Tue, 7 Sep 2010 20:41:14 -0400,
Kasper Daniel Hansen <kasperdanielhansen at gmail.com> wrote:

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