As you already know, R is primarily a functional language; it also supports OOP. OOP in R is an archetype wherein objects and their interactions are used to design various generic functions. It defines the process of constructing modular bits of code, which can be integrated to form a large function. Some key concepts related to OOP are as follows:
R supports three forms of OOP systems based on different objects, classes, and methods:
lm()
function for its corresponding method:
Figure 3.8: Generic S3 functions for different methods
new()
function, and class components are defined using the setClass()
function. A class has three main properties:employee
class of shop will be represented by a name
represented as character
, age
as numeric
, and gender
represented as character
as shown below:representation(name="character", age="numeric", gender="character")
contains
in S4 as it makes method lookup intricate.The following table compares the S3, S4, and R5 systems:
Figure 3.9: A comparison between S3, S4 and R5 OOs