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? 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? 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? Insightful? I use old-style (S version3 engine) and new-style (S version4) classes in the sense of Venables and Ripley. ------------------------------------- Dr Jonathan Swinton Proteom Ltd Babraham Hall Babraham Cambridge CB2 4AT www.proteom.com -----------------------------------
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 thenew 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 ofhttp://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? Insightful? 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@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
On Tue, 1 Apr 2003 14:33:39 +0100 Jonathan Swinton <jswinton@proteom.com> 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? > > 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? > > 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? Insightful? > > I use old-style (S version3 engine) and new-style (S version4) classes in the sense of Venables and Ripley. > > ------------------------------------- > Dr Jonathan Swinton > Proteom Ltd > Babraham Hall > Babraham > Cambridge CB2 4AT > www.proteom.com > >Jonathan, I think you are asking the right questions. SV4 has caused severe problems in S-Plus mainly due to lack of multiple inheritance. I have been burned MANY times when running an object through a method (e.g., imputation) that sticks on an additional class. Right now I am teaching a class using S-Plus 6 with my impute function in the Hmisc library and strange error messages are driving the students crazy. So far all my tests in the R 1.7 development version indicate that R, unlike S-Plus, is backward compatible with old-style classes and methods. But if you want to be compatible with S-Plus it would be nice if we could just avoid new classes and methods. Unfortunately S-Plus does not let us do that either, because multiple old-style classes is not allowed any more. In the bigger picture, I am still not really convinced that new classes and methods offer advantages to data analysts. The new methods are not as flexible and take longer to program. I frequently stick on a new element of a fit object list for debugging or for enhancing functions that others wrote. You can't really do this with SV4. Also, new methods and classes have made some code non-transportable across systems (primarily to older versions of S-Plus). There are now packages on CRAN that use slots to address elements while other versions of these same packages use list elements. Hence some code retrieves details of fit objects using @ and some needs to use $. I know that retrieving pieces of fit objects is inelegant (extractor methods should be written) but it is very common that I don't want to take the time to write an extractor method for every application, and I sure hate to waste time sensing whether the object was created using old vs. new style classes. I know that new classes and methods are more elegant from a computer science perspective, but I analyze data and like to use what works (e.g., I really like both Perl and Python). New methods provide much more safety. I have found though that I don't need this kind of protection from myself. I have plenty of other problems to worry about. That's my $.02 worth. -- Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat ______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help