setOldClass {methods} | R Documentation |
The Classes
argument is an old-style class assignment. In
particular, if there is more than one name, we expect old-style
class inheritance. Calling setOldClass
establishes similar
inheritance for formal method dispatch, so that the class names can
be used in a call to setMethod
.
setOldClass(Classes, where = 1)
Classes |
A character vector of names for old-style classes. |
where |
Where to store the class definitions. |
Each of the names will be defined as a virtual class, extending the
remaining classes in Classes
, and the class
oldClass
, which is the “root” of all old-style classes.
See Methods for the details of method dispatch and inheritance.
The list .OldClassesList
contains the old-style classes that
are defined by the methods package. Each element of the list is an
old-style list, with multiple character strings if inheritance is
included.
Each element of the list was passed to setOldClass
when
creating the methods package; therefore, these classes can be used
in setMethod
calls, with the inheritance as implied by
the list.
setClass
, setMethod
setOldClass(c("mlm", "lm"))
setGeneric("dfResidual", function(model)standardGeneric("dfResidual"))
setMethod("dfResidual", "lm", function(model)model$df.residual)
## dfResidual will work on mlm objects as well as lm objects
myData <- data.frame(time = 1:10, y = (1:10)^.5)
myLm <- lm(cbind(y, y^3) ~ time, myData)
rm(myData, myLm)
removeGeneric("dfResidual")
removeClass("mlm")
removeClass("lm")