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

Inheritance

Inheritance is also more familiar when working with the R6 object model. In this case, you can simply add the inherit parameter to the R6Class() function call, and you may call the initialize method for the superclass by using super$initialize(). In this case, we use that technique to provide a more intuitive constructor interface to the user: a single value for length in the case of a square, instead of having to repeat the same value twice, which can be prone to counter-intuitive behavior if not checked. We can also override the print() method, just as we would normally add another method:

R6Square <- R6Class(    "R6Square",    inherit = R6Rectangle,    public = list(        initialize = function(a, color) {            super$initialize(a, a, color) }, ...
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