December 2017
Beginner to intermediate
470 pages
12h 29m
English
Creating a subclass is easy; we simply need to call the setClass() function as we did before, and send the contains parameter with the name of the class it will inherit from. S4 supports multiple inheritance, but it's not something we're going to look at. The interested reader is encouraged to look into the documentation.
An interesting feature of S4 classes is that if a class extends one of R's basic types, there will be a slot called .Data containing the data from the basic object type. Code that works on the basic object type will work directly on the .Data part of the object, so it makes our programming a bit easier:
setClass("S4Square", contains = "S4Rectangle")
Note that when we instantiate the S4Square class, we will need ...