In Object-Oriented Programming (OOP) of R Language, encapsulation means binding of the data and methods inside a class. R6 package is an encapsulated OOP system that helps us use encapsulation in R. R6 package provides R6 class which is similar to the reference class in R but is independent of the S4 classes. Along with the private and public members, R6 Classes also support inheritance even if the classes are defined in different packages. Some of the popular R packages that use R6 classes are
 2  5
Both public and private members can be used. The queue (
elements) is private so that the object can not modify it externally. The initialize function is the constructor for initializing the object.
object$member is used for accessing the public members outside the class whereas
private$member is used for accessing the private members inside the class methods.
self refers to the object that has called the method.
The following example is a demonstration of Inheritance in R6 classes by creating another class childQueue that inherits the class Queue.
 2  3
childQueue class can use
dequeue() functions from the Queue super class. size method overrides the
size() from super class Queue but calls
size() of Queue internally using
super. These classes can be inherited across packages.
- Classes in R Programming
- How to create static classes in PHP ?
- Getting the Modulus of the Determinant of a Matrix in R Programming - determinant() Function
- Set or View the Graphics Palette in R Programming - palette() Function
- tidyr Package in R Programming
- Get Exclusive Elements between Two Objects in R Programming - setdiff() Function
- Intersection of Two Objects in R Programming - intersect() Function
- Add Leading Zeros to the Elements of a Vector in R Programming - Using paste0() and sprintf() Function
- Clustering in R Programming
- Compute Variance and Standard Deviation of a value in R Programming - var() and sd() Function
- Compute Density of the Distribution Function in R Programming - dunif() Function
- Compute Randomly Drawn F Density in R Programming - rf() Function
- Data Handling in R Programming
- Return a Matrix with Lower Triangle as TRUE values in R Programming - lower.tri() Function
- Print the Value of an Object in R Programming - identity() Function
- Check if Two Objects are Equal in R Programming - setequal() Function
- Random Forest with Parallel Computing in R Programming
- R - Object Oriented Programming
- Check for Presence of Common Elements between Objects in R Programming - is.element() Function
- Check if Elements of a Vector are non-empty Strings in R Programming - nzchar() Function