From ross at biostat.ucsf.edu  Tue Jun 30 21:58:32 2009
From: ross at biostat.ucsf.edu (Ross Boylan)
Date: Tue, 30 Jun 2009 12:58:32 -0700
Subject: [Rd] S4 class redefinition
Message-ID: <1246391912.26310.315.camel@corn.betterworld.us>

I haven't found much on S4 class redefinition; the little I've seen
indicates the following is to be expected:
1. setClass("foo", ....)
2. create objects of class foo.
3. execute the same setClass("foo", ...) again (source the same file).
4. objects from step 2 are now NULL.

Is that the expected behavior (I ran under R 2.7.1)?

Assuming it is, it's kind of unfortunate.  I can wrap my setClass code
like this
if (! isClass("foo")) setClass("foo", ....)
to avoid this problem.  I've seen this in other code; is that the
standard solution? 

I thought that loading a library was about the same as executing the
code in its source files (assuming R only code).  But if this were true
my saved objects would be nulled out each time I loaded the
corresponding library.  That does not seem to be the case.  Can anyone
explain that?

Do I need to put any protections around setMethod so that it doesn't run
if the method is already defined?

At the moment I'm not changing the class defintion but am changing the
methods, so I can simply avoid running setClass.

But if I want to change the class, most likely by adding a slot, what do
I do?  At the moment it looks as if I'd need to make a new class name,
define some coerce methods, and then locate and change the relevant
instances.  Is there a better way?

Thanks.
Ross Boylan



[Rd] S4 class redefinition
Ross Boylan