S3 and S4 classesBased on years of experience in Bioconductor, it is fair to say that S4 classes have been very successful in this project. S4 classes has allowed us to construct rich and complicated data representations that nevertheless seems simple to the end user. An example, which we will return to, are the data containers ExpressionSet and SummarizedExperiment.
Let us look at a S3 object, the output of the linear model function lm in base R:
In standard R, an S3 object is essentially a list with a class attribute on it. The problem with S3 is that we can assign any class to any list, which is nonsense. Let us try an example
At least we don’t get an error when we print it.
S4 classes have a formal definition and formal validity checking. To the end user, this gurantees validity of the object.