Reference classes are a new (as of R 2.12) way of object-oriented programming in R, such that objects are not copied but are instead mutable. Like most pass-by-reference methodologies, they are particularly well-suited to work with large datasets.
R has three object oriented (OO) systems: S3, S4 and Reference Classes (sometimes referred to as R5, yet their official name is Reference Classes).
Reference Classes were introduced in R 2.12. They fill a long standing need for mutable objects that had previously been filled by non-core packages like R.oo, proto and mutatr.
There are two main differences between reference classes and S3 and S4:
- Refclass objects use message-passing OO
- Refclass objects are mutable: the usual R copy on modify semantics do not apply
These properties makes this object system behave much more like Java and C#. The implementation of reference classes is almost entirely in R code, they are a combination of S4 methods and environments.
See also