A method defined for an individual member of the group takes precedence over a method defined for the group as a whole.
## S3 methods for group generics have prototypes: Math(x, ...) Ops(e1, e2) Complex(z) Summary(..., na.rm = FALSE)
- x, z, e1, e2
- further arguments passed to methods.
- logical: should missing values be removed?
There are four groups for which S3 methods can be written, namely the
"Complex" groups. These are not R objects in base R, but methods can be supplied for them and base R contains
difftime methods for the first three groups. (There is also a
ordered method for
Date methods for
package_version methods for
Summary, as well as a
ts method for
Ops in package stats.)
This group contains both binary and unary operators (
!): when a unary operator is encountered the
Opsmethod is called with one argument and
The classes of both arguments are considered in dispatching any member of this group. For each argument its vector of classes is examined to see if there is a matching specific (preferred) or
Opsmethod. If a method is found for just one argument or the same method is found for both, it is used. If different methods are found, there is a warning about ‘incompatible methods’: in that case or if no method is found for either argument the internal method is used.
If the members of this group are called as functions, any argument names are removed to ensure that positional matching is always used.
Members of this group dispatch on the first argument supplied.
Members of this group dispatch on
Note that a method will be used for one of these groups or one of its members only if it corresponds to a
"class" attribute, as the internal code dispatches on
oldClass and not on
class. This is for efficiency: having to dispatch on, say,
Ops.integer would be too slow.
The number of arguments supplied for primitive members of the
"Math" group generic methods is not checked prior to dispatch.
There is no lazy evaluation of arguments for group-generic functions.
These functions are all primitive and internal generic.
The details of method dispatch and variables such as
.Generic are discussed in the help for
UseMethod. There are a few small differences:
- For the operators of group
Ops, the object
.Methodis a length-two character vector with elements the methods selected for the left and right arguments respectively. (If no method was selected, the corresponding element is
.Grouprecords the group used for dispatch (if a specific method is used this is
Appendix A, Classes and Methods of
Chambers, J. M. and Hastie, T. J. eds (1992) Statistical Models in S. Wadsworth & Brooks/Cole.
Package methods does contain objects with these names, which it has re-used in confusing similar (but different) ways. See the help for that package.
methods for methods of non-internal generic functions.
S4groupGeneric for group generics for S4 methods.
Documentation reproduced from R 3.0.2. License: GPL-2.