-
Notifications
You must be signed in to change notification settings - Fork 755
R has three object oriented (OO) systems: S3, S4 and R5. This page describes R5, the newest reference based .
R5, or reference classes, are brand new 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 R5 and S3/S4:
- R5 objects use message-passing OO
- R5 objects are mutable: the usual R copy on modify semantics do not apply
Surprisingly, the implementation of R5 is almost entirely in R code - they are a combination of S4 methods and environments.
setRefClass(Class, fields)
Inheritance: setRefClass(Class, contains )
Adding new methods after creation: obj$methods
Adding new fields after creation: obj$fields
Note: collation Note: namespaces and exporting Note: documentation
Note: using reference based classes: want to minimise side effects. Encapsulate. Majority of functions should still be side effect free.