S4 Classes
Some programmers feel that S3 does not provide the safety normally associated with OOP. For example, consider our earlier employee database example, where our class "employee" had three fields: name, salary, and union. Here are some possible mishaps:
We forget to enter the union status.
We misspell union as onion.
We create an object of some class other than
"employee"but accidentally set itsclassattribute to"employee".
In each of these cases, R will not complain. The goal of S4 is to elicit a complaint and prevent such accidents.
S4 structures are considerably richer than S3 structures, but here we present just the basics. Table 9-1 shows an overview of the differences between the two classes.
Table 9-1. Basic R Operators
Operation ... |
|---|
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.
Read now
Unlock full access