[R] Need Advice: Considering Converting a Package from S3 to S4

Bryan Hanson hanson at depauw.edu
Mon Aug 10 17:03:27 CEST 2009

Hello R Folks...  

Not a technical question, but I need some advice and perspective.

I¹ve got a set of functions I¹m planning to put together into a package.
The main hunk of data that gets used by different functions is currently an
S3 list.  I¹ve been reading about S4 objects, and I see the (numerous)
advantages of them.  I have seen the recommendation that all new packages be
done with S4.  Before I get much farther, I need to decide if I will go to
S4 for this central hunk of data.

My questions are about making the conversion, whether it is worth the
trouble and what pitfalls I might encounter.  I can easily (re)define my key
list as an S4 object.  But after that...

1.  It seems the the simplest/minimalist approach is to update all the
functions so that where I use ³data$element² I replace it with ³data at slot².
Is it really this easy, or have I missed something?  Easy or not, this by
itself doesn't take advantage of much, except the ability to define
subclasses at a later date (maybe that is sufficient reason though).

2.  I also see in my reading that I should consider writing accessor
functions for my object.  What I can't quite see is why I would want to do
this, if I can get the contents with "data at slot"?  What am I missing here?

3. At this point, I'm not sure that I would write specific methods for this
proposed S4 object.  It would not be necessary in the short run.  Making it
S4 would mainly allow for "future expansion" as they say.  If methods are
not critical, does it make sense to spend the time making the change?

Any perspective and advice would be welcomed.  Thanks in advance, Bryan
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA

More information about the R-help mailing list