[Rd] Re: [S] Old style and new style classes

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Apr 1 15:57:30 MEST 2003

On Tue, 1 Apr 2003, Jonathan Swinton wrote:

> I have been writing quick and dirty S-plus code for years, but for a
> recent project I took the plunge, bought Venables and Ripley's S
> Programming, and implemented a class library using new style classes (in
> S-Plus 6.0). It worked quite nicely and I am wondering about making more
> routine use of them. Before I make much more of an investment, I have a
> few questions, both factual and subjective, that I'd be grateful for
> opinions on.

> 1) I don't use R at the moment, but I might, and might want to target
> users who do. The documentation at
> http://cran.r-project.org/doc/manuals/R-lang.pdf seems to suggest that R
> 1.6.2 supports only old style classes, but
> http://developer.r-project.org/methodsPackage.html implies that new
> style classes can be used with the aid of a methods package from John
> Chambers. Venables and Ripley only describe old-style classes for R and
> add in their online supplement that there are 'small changes' between 
> S-Plus and R for new style classes. Can the new style class mechanism be 
> used in practice transparently and portably between S-Plus and R?

R did not support S4 classes in 1999 when S Programming was written.
It does now, and as from version 1.7.0 (due April 16) it will support
them by default as the "methods" package will be loaded by default.

My experience is that those small differences have been a big disincentive
to portability.  There has recently been a big push to getting S4 classes
working well in R, but the details still catch me out a lot.
It is not clear that the R implementation is converging towards the S-PLUS 
6.x one, though.

> 2) The s-news archives hold a few complaints about the design of the
new style classes scattered over the last few years. On mature reflection, 
do people have opinions about the practical workability of old or new style 
classes for implementing reusable, object oriented code?

I think it is too early for `mature reflection': see my next answer.

> 3) There are also some hints (eg top line of 
http://developer.r-project.org/classIssues.html) that new style classes 
have not been committed to by some active developers. Is this true? 
Do new style classes have an active future? Is R committed to them?   

A very small proportion of active developers have been using them. Only
about 6 of the 206 packages on CRAN use them and 4 of those are variations
on the DBI theme.  There are very few third-party uses of S4 classes
available for S-PLUS 6.x.  (The BioConductor project uses S4 classes under
R, and there is an S-PLUS product based on that which I suppose does too.)

There is a lot more current interest in S4 classes in the R community: 
time will tell if this blossoms or dies off.

Until recently the desire to make code available for S-PLUS 2000 and R
was a major impediment to using S4 classes, but soon it will be reasonable 
to assume that most users have them available.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list