Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of the new Reference Classes?

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?

like image 451
Ari B. Friedman Avatar asked Feb 28 '11 00:02

Ari B. Friedman


People also ask

What is a reference class in programming?

Reference class in R programming is similar to the object oriented programming we are used to seeing in common languages like C++, Java, Python etc. Unlike S3 and S4 classes, methods belong to class rather than generic functions. Reference class are internally implemented as S4 classes with an environment added to it.

How are reference classes passed to functions in R?

Reference classes inherit from other reference classes by using the standard R inheritance; that is, by including the superclasses in the contains= argument when creating the new class. The names of the reference superclasses are in slot refSuperClasses of the class definition.


1 Answers

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:

  • John's presentation in November 2010 at Stanford
  • Martin Morgan in November 2010 from the BioConductor Europe meetings
  • Romain and myself mention it in the Google Tech Talk on Rcpp

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.

like image 130
Dirk Eddelbuettel Avatar answered Oct 10 '22 00:10

Dirk Eddelbuettel