You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Objects are not limited to a single class, and can have many classes: class(x) <- c("A", "B") class(x) <- LETTERS
As discussed in the next section, R looks for methods in the order in which they appear in the class vector. So in this example, it would be like class A inherits from class B - if a method isn’t defined for A, it will fall back to B. However, if you switched the order of the classes, the opposite would be true! http://adv-r.had.co.nz/S3.html
In visR, I noticed that some classes are defined in the opposite order: the most generic class is defined first and the specific visR classes are last. In the example below, we see that the ggplot classes are listed first, meaning that if ggplot2 were to ever implement a visr() method for class "ggplot" it would take precedent over the visR-defined method functions.
Generally, you want the most broad class listed last, and the most narrow and specific class should be listed first to ensure the S3 dispatch system selects the most appropriate method. So the classes below should be defined as c("ggsurvfit", "gg", "ggplot")
Quoting from the Advanced R book:
In visR, I noticed that some classes are defined in the opposite order: the most generic class is defined first and the specific visR classes are last. In the example below, we see that the ggplot classes are listed first, meaning that if ggplot2 were to ever implement a
visr()
method for class "ggplot" it would take precedent over the visR-defined method functions.Generally, you want the most broad class listed last, and the most narrow and specific class should be listed first to ensure the S3 dispatch system selects the most appropriate method. So the classes below should be defined as
c("ggsurvfit", "gg", "ggplot")
Created on 2022-03-24 by the reprex package (v2.0.1)
As an example, the Hmisc package adds the class "labelled" to labelled objects. The new labelled class is added to the beginning.
Created on 2022-03-26 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: