ID EN
Miscellaneous

groupGeneric

R Base 3.6.2

Group generic methods can be defined for four pre-specified groups of functions, Math, Ops, Summary and Complex. (There are no objects of these names in base R, but there are in the methods package.) A method defined for an individual member of the group takes precedence over a method defined for the group as a whole.

Syntax

R
## S3 methods for group generics have prototypes:
<code>Math(x, \dots)</code>
<code>Ops(e1, e2)</code>
<code>Complex(z)</code>
<code>Summary(\dots, na.rm = FALSE)</code>

Arguments

Parameter Description
x, z, e1, e2 objects.
&#8230; further arguments passed to methods.
na.rm logical: should missing values be removed?

Details

There are four groups for which S3 methods can be written, namely the "Math", "Ops", "Summary" and "Complex" groups. These are not R objects in base R, but methods can be supplied for them and base R contains factor, data.frame and difftime methods for the first three groups. (There is also a ordered method for Ops, POSIXt and Date methods for Math and Ops, package_version methods for Ops and Summary, as well as a ts method for Ops in package stats.) Group "Math": abs, sign, sqrt, floor, ceiling, trunc, round, signif exp, log, expm1, log1p, cos, sin, tan, cospi, sinpi, tanpi, acos, asin, atan cosh, sinh, tanh, acosh, asinh, atanh lgamma, gamma, digamma, trigamma cumsum, cumprod, cummax, cummin Members of this group dispatch on x. Most members accept only one argument, but members log, roun

Examples

Example
R
# NOT RUN {
require(utils)

d.fr <- data.frame(x = 1:9, y = stats::rnorm(9))
class(1 + d.fr) == "data.frame" ##-- add to d.f. ...

methods("Math")
methods("Ops")
methods("Summary")
methods("Complex")  # none in base R
# }

See Also

methods for methods of non-internal generic functions. S4groupGeneric for group generics for S4 methods.