\HeaderA{groupGeneric}{S3 Group Generic Functions}{groupGeneric}
\aliasA{.Group}{groupGeneric}{.Group}
\aliasA{Complex}{groupGeneric}{Complex}
\aliasA{group generic}{groupGeneric}{group generic}
\aliasA{Math}{groupGeneric}{Math}
\methaliasA{Math.data.frame}{groupGeneric}{Math.data.frame}
\aliasA{Ops}{groupGeneric}{Ops}
\methaliasA{Ops.data.frame}{groupGeneric}{Ops.data.frame}
\aliasA{S3groupGeneric}{groupGeneric}{S3groupGeneric}
\aliasA{Summary}{groupGeneric}{Summary}
\methaliasA{Summary.data.frame}{groupGeneric}{Summary.data.frame}
\keyword{methods}{groupGeneric}
\begin{Description}\relax
Group generic methods can be defined for four pre-specified groups of
functions, \code{Math}, \code{Ops}, \code{Summary} and \code{Complex}.
(There are no objects of these names in base \R, but there are in the
\pkg{methods} package.)

A method defined for an individual member of the group takes
precedence over a method defined for the group as a whole.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 methods for group generics have prototypes:
Math(x, ...)
Ops(e1, e2)
Complex(z)
Summary(..., na.rm = FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, z, e1, e2}] objects.
\item[\code{...}] further arguments passed to methods.
\item[\code{na.rm}] logical: should missing values be removed?
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
There are four \emph{groups} for which S3 methods can be written,
namely the \code{"Math"}, \code{"Ops"}, \code{"Summary"} and
\code{"Complex"} groups.  These are not \R{} objects, but methods can be
supplied for them and base \R{} contains \code{\LinkA{factor}{factor}},
\code{\LinkA{data.frame}{data.frame}} and \code{\LinkA{difftime}{difftime}} methods for
the first three groups.  (There is also a \code{\LinkA{ordered}{ordered}}
method for \code{Ops}, \code{\LinkA{POSIXt}{POSIXt}} and \code{\LinkA{Date}{Date}}
methods for \code{Math} and \code{Ops}, \code{\LinkA{package\_version}{package.Rul.version}}
methods for \code{Ops} and \code{Summary}, as well as a
\code{\LinkA{ts}{ts}} method for \code{Ops} in package \pkg{stats}.)

\Enumerate{
\item Group \code{"Math"}:
\Itemize{
\item
\code{abs}, \code{sign}, \code{sqrt},\\
\code{floor}, \code{ceiling}, \code{trunc},\\
\code{round}, \code{signif}

\item
\code{exp}, \code{log},  \code{expm1}, \code{log1p},\\
\code{cos}, \code{sin}, \code{tan},\\
\code{acos}, \code{asin}, \code{atan}

\code{cosh}, \code{sinh}, \code{tanh},\\
\code{acosh}, \code{asinh}, \code{atanh}

\item
\code{lgamma}, \code{gamma}, \code{digamma}, \code{trigamma}

\item \code{cumsum}, \code{cumprod}, \code{cummax}, \code{cummin}
}
Members of this group dispatch on \code{x}.  Most members accept
only one argument, but members \code{log}, \code{round} and
\code{signif} accept one or two arguments, and \code{trunc} accepts
one or more.

\item Group \code{"Ops"}:
\Itemize{
\item
\code{"+"}, \code{"-"}, \code{"*"}, \code{"/"},
\code{"\textasciicircum{}"}, \code{"\%\%"}, \code{"\%/\%"}

\item \code{"\&"}, \code{"|"}, \code{"!"}

\item \code{"=="}, \code{"!="},
\code{"<"}, \code{"<="}, \code{">="}, \code{">"}
}
This group contains both binary and unary operators (\code{+},
\code{-} and \code{!}): when a unary operator is encountered the
\code{Ops} method is called with one argument and \code{e2} is
missing.

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
\code{Ops} method.  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
\sQuote{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.

\item Group \code{"Summary"}:
\Itemize{
\item \code{all}, \code{any}
\item \code{sum}, \code{prod}
\item \code{min}, \code{max}
\item \code{range}
}
Members of this group dispatch on the first argument supplied.

\item Group \code{"Complex"}:
\Itemize{
\item \code{Arg}, \code{Conj}, \code{Im}, \code{Mod}, \code{Re}
}
Members of this group dispatch on \code{z}.
}

Note that a method will used for either one of these groups or one of
its members \emph{only} if it corresponds to a \code{"class"}
attribute, as the internal code dispatches on \code{\LinkA{oldClass}{oldClass}}
and not on \code{\LinkA{class}{class}}.  This is for efficiency: having to
dispatch on, say, \code{Ops.integer} would be too slow.

The number of arguments supplied for primitive members of the
\code{"Math"} group generic methods is not checked prior to dispatch.

There is no lazy evaluation of arguments for group-generic functions.
\end{Details}
\begin{Section}{Technical Details}
These functions are all primitive and \LinkA{internal generic}{internal generic}.

The details of method dispatch and variables such as \code{.Generic}
are discussed in the help for \code{\LinkA{UseMethod}{UseMethod}}.  There are a
few small differences:
\Itemize{
\item For the operators of group \code{Ops}, the object
\code{.Method} is 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 \code{""}.)
\item Object \code{.Group} records the group used for dispatch (if
a specific method is used this is \code{""}).
}
\end{Section}
\begin{References}\relax
Appendix A, \emph{Classes and Methods} of\\
Chambers, J. M.  and Hastie, T. J. eds (1992)
\emph{Statistical Models in S.}
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{methods}{methods}} for methods of non-Internal generic functions.

\LinkA{S4groupGeneric}{S4groupGeneric} for group generics for S4 methods.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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
\end{ExampleCode}
\end{Examples}

