S3 terminology: Subclass/Superclass

Maybe someone can help me here a bit with terminology. Say I have an object with the following class attribute:

c("myclass", "data.table", "data.frame")

would it be ok to say that "myclass" is a subclass of "data.table", and "data.frame" is the parent class of both? or would it be the other way round? or should i try to avoid this terminology with S3 classes alltogether?

I am pretty sure the superclass and subclass terminology from S4 classes and general programming lingo apply to S3 classes too. See R Class Definitions for details.

For example:

df <- tibble(
    x = c(1,2),
    y = c("a","b")



> df
# A tibble: 2 x 2
      x     y
  <dbl> <chr>
1     1     a
2     2     b
> class(df)
[1] "tbl_df"     "tbl"        "data.frame"
> getClass('tbl_df')
Virtual Class "tbl_df" [package "tibble"]

Name:                .Data               names           row.names            .S3Class
Class:                list           character data.frameRowLabels           character

Class "tbl", directly
Class "data.frame", by class "tbl", distance 2
Class "list", by class "tbl", distance 3
Class "oldClass", by class "tbl", distance 3
Class "vector", by class "tbl", distance 4

Known Subclasses: "grouped_df", "rowwise_df"

So, yeah, myclass is a subclass of data.table and data.frame. And data.frame is the superclass of data.table.

1 Like

I'ld also say, that you are (almost) correct, as explained above.

For questions like these, you might also want to look into the S3 chapter of the development version of Hadley's Advanced R book, where quite a bit of formalism for S3 is introduced. For the original question I would look under inheritance.