December 2017
Beginner to intermediate
470 pages
12h 29m
English
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) }, ...