Skip to Content
R Programming By Example
book

R Programming By Example

by Omar Trejo Navarro
December 2017
Beginner to intermediate
470 pages
12h 29m
English
Packt Publishing
Content preview from R Programming By Example

Encapsulation and mutability

Since we placed the a, b, and own_color in the private list in the class definition, they remain private, and this is how encapsulation is enforced in R6. As you can see, we were not allowed to assign directly to the a attribute as we expected, since it was placed in the private list. This makes sure that we can't have attributes or methods marked as private directly from outside the object, and prevents us from making bad decisions when coding. This is a great advantage of the R6 model.

Encapsulation in R6 is achieved through environments.

Mutability is achieved by using setters (methods used to change a class's attribute). Notice that in this case, we don't need to reassign the resulting object as we do with ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Efficient R Programming

Efficient R Programming

Colin Gillespie, Robin Lovelace
R Programming

R Programming

Jared P. Lander

Publisher Resources

ISBN: 9781788292542Supplemental Content