[1] "integer"
[1] "base"
2026-04-02
What is Object Oriented Programming?
OOP models in R
Idea of object oriented programming is that the user can define abstract objects (classes, e.g. a linear model object) that contains named ‘pieces’ (fields, e.g. the data, the parameter estimates, residuals, …) and associated ‘methods’ (functions, e.g. predict)
Polymorphism allows us to ‘over-write’ existing methods and implement specialized functionality that way
Methods have the form class.methodname - at the core of R and lazy evaluation: e.g. summary, print, …
In chronological order:
base
S3
S4
R6
Check any object in R for its class/type with typeof or sloop::otype
ggplot2 is a based on grid and uses S3:
shiny uses R6
lme4, stats4 use S4
make an S3 object: give an object a class:
Good practice, but not required: constructor new_classname
Validator: check that object is ‘right’