R and object oriented programming

S3 classes

  • Not really objects, more of a naming convention
  • Based around the . syntax: E.g. for print, print calls print.lm print.anova, etc. And if not found,print.default

S4 classes

Reference classes

proto

  • ggplot2 was originally written in proto, but will eventually be rewritten using S3.
  • Neat concept (prototypes, not classes), but seems tricky in practice
  • Next version of ggplot2 seems to be moving away from it
  • Description of the concept and implementation

R6 classes

  • By-reference
  • Does not depend on S4 classes
  • Creating an R6 class is similar to the reference class, except that there’s no need to separate the fields and methods, and you can’t specify the types of the fields.”

Leave a Comment