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

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 ...

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