What is the significance of the new Reference Classes?
Asked Answered
A

1

48

Apparently John Chambers added Reference Classes to R in version 2.12. There doesn't appear to be much information online yet, but they're calling them R5 classes, which implies they're on a level with S3 and S4 classes.

Question: What is a reference class, and how does this fit in with existing class types?

Anergy answered 28/2, 2011 at 0:47 Comment(6)
I think "R5" was a kind of joke made during an Rcpp presentation - partly as the need for a brand new R was being discussed at the time, I don't think it's a serious name. The Reference Classes fit squarely in R's S4 afaik. Searching for "R5" in SO [r] chat gives chat.stackoverflow.com/search?q=R5&room=106Mamelon
Reference based means the objects are mutable - changes don't make copies.Edisonedit
In fact, much depends on what you want to do. S4 comes in handy sometimes (especially the dispatching and more rigorous check of objects). Reference classes seem ideal for work with huge datasets that need transformation prior to analysis. But for the rest, I'd like my objects untouched.Purview
@Joris: Makes sense. It is a bit frustrating that there are now three not-really-compatible OO systems for R. I'd rather learn one and learn it right. So I tend to stick with S3 classes. Even I can see the limitations of them, but they're so simple to use it's seductive. If S4 classes got more consistent praise I would put in the effort to really learn them.Anergy
It looks like Reference Classes are progressing nicely in R core. trace now (R 2.13.1) supports them.Anergy
And for more info on RCs in other languages: programmers.stackexchange.com/questions/57068/…Anergy
K
35

The request for documentation for ReferenceClasses comes up every now and then, for example on the r-devel list. The best answer so far is to actually look at what help(ReferenceClasses) gives you---which is a pretty decent start.

Then there are a few presentations:

And as noted by mdsummer in the comment, R5 was a short-lived joke. There was already another R-related project called R5, and John much prefers ReferenceClasses. And I reckon they are here to stay. People use them already as e.g. Jeff Horner is his new Rack package.

Kenrick answered 28/2, 2011 at 2:5 Comment(8)
Ok, so they're not R5 classes but ReferenceClasses, and they look a lot like a fuller implementation of object oriented ideas than S3 classes were. I'll look more through the links and try to wrap my head around them. Thanks for the point in the right direction.Anergy
R5 methods are associated with classes whereas S3 methods are associated with generic functions. R5 is different more than fuller or better than S3.Collaborative
Yes but they are still not called R5 but ReferenceClasses. R5 is something Simon once did and has no relationship.Kenrick
They should be "R8Classes" (in the spirit of I18n and L10n)Knives
Or if we like them enough, "GR8classes"!Anergy
@DirkEddelbuettel, I think you mean Jeffrey Horner's new Rook package.Fivestar
Yes and no. Rack preceded it / was a temporary name til Jeff renamed it.Kenrick
@DirkEddelbuettel Dirk, are you aware of any more recent (ahem) reference materials on reference classes? Pointers to source code that makes extensive use of reference classes are perfectly acceptable.Carpio

© 2022 - 2024 — McMap. All rights reserved.