14.2 Introducing R6

  • R6 classes are not built into base.
    • It is a separate package.
    • You have to install and attach to use.
    • If R6 objects are used in a package, it needs to be specified as a dependency in the DESCRIPTION file.
install.packages("R6")
library(R6)
  • R6 classes have two special properties:
    1. Uses an encapsulated OOP paradigm.
      • Methods belong to objects, not generics.
      • They follow the form object$method() for calling fields and methods.
    2. R6 objects are mutable.
      • Modified in place.
      • They follow reference semantics.
  • R6 is similar to OOP in other languages.
  • However, its use can lead ton non-idiomatic R code.
    • Tradeoffs - follows an OOP paradigm but sacrafice what users are use to.
    • Microsoft365R.