\Header{groupGeneric}{Group Generic Functions}
\alias{.Class}{groupGeneric}
\alias{.Generic}{groupGeneric}
\alias{.Group}{groupGeneric}
\alias{.Method}{groupGeneric}
\alias{Arith}{groupGeneric}
\alias{Compare}{groupGeneric}
\alias{Complex}{groupGeneric}
\alias{Math}{groupGeneric}
\methalias{Math.data.frame}{groupGeneric}
\methalias{Math.factor}{groupGeneric}
\alias{Math2}{groupGeneric}
\alias{Ops}{groupGeneric}
\methalias{Ops.data.frame}{groupGeneric}
\methalias{Ops.factor}{groupGeneric}
\methalias{Ops.ordered}{groupGeneric}
\alias{Summary}{groupGeneric}
\methalias{Summary.data.frame}{groupGeneric}
\methalias{Summary.factor}{groupGeneric}
\keyword{methods}{groupGeneric}
\begin{Description}\relax
Group generic functions can be defined with either S3 and S4 methods
(with different groups).  Methods are defined for the group of functions
as a whole.

A method defined for an individual member of the group takes
precedence over a method defined for the group as a whole.

When package \pkg{methods} is attached there are objects visible with
the names of the group generics: these functions should never be
called directly (a suitable error message will result if they are).\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 methods have prototypes:
Math(x, ...)
Ops(e1, e2)
Summary(x, ...)

## S4 methods have prototypes:
Arith(e1, e2)
Compare(e1, e2)
Ops(e1, e2)
Math(x)
Math2(x, digits)
Summary(x, ..., na.rm = FALSE)
Complex(z)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, z, e1, e2}] objects.
\item[\code{digits}] number of digits to be used in \code{round} or \code{signif}.
\item[\code{...}] further arguments passed to or from methods.
\item[\code{na.rm}] logical: should missing values be removed?
\end{ldescription}
\end{Arguments}
\begin{Section}{S3 Group Dispatching}
There are three \emph{groups} for which S3 methods can be written, namely
the \code{"Math"}, \code{"Ops"} and \code{"Summary"} groups.  These
are not \R{} objects, but methods can be supplied for them and base \R{}
contain \code{\Link{factor}} and \code{\Link{data.frame}} methods.
(There is also a \code{\Link{ordered}} method for \code{Ops}.)


\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{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{gammaCody},\\
\code{digamma}, \code{trigamma}, \code{tetragamma},
\code{pentagamma}

\item \code{cumsum}, \code{cumprod}, \code{cummax}, \code{cummin}
}

\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{">"}
}

\item Group \code{"Summary"}:
\Itemize{
\item \code{all}, \code{any}
\item \code{sum}, \code{prod}
\item \code{min}, \code{max}
\item \code{range}
}
}

The number of arguments supplied for \code{"Math"} group generic
methods is not checked prior to dispatch. (Prior to \R{} 1.7.0, all
those whose default method has one argument were checked, but the
others were not.)\end{Section}
\begin{Section}{S4 Group Dispatching}
When package \pkg{methods} is attached, formal (S4) methods can be
defined for groups.

The functions belonging to the various groups are as follows:
\describe{
\item[\code{Arith}] \code{"+"}, \code{"-"}, \code{"*"}, \code{"\textasciicircum{}"},
\code{"\%\%"}, \code{"\%/\%"}, \code{"/"}
\item[\code{Compare}] \code{"=="}, \code{">"}, \code{"<"},
\code{"!="}, \code{"<="}, \code{">="}
\item[\code{Ops}] \code{"Arith"}, \code{"Compare"}
\item[\code{Math}] \code{"log"}, \code{"sqrt"}, \code{"log10"},
\code{"cumprod"}, \code{"abs"}, \code{"acos"}, \code{"acosh"},
\code{"asin"}, \code{"asinh"}, \code{"atan"}, \code{"atanh"},
\code{"ceiling"}, \code{"cos"}, \code{"cosh"}, \code{"cumsum"},
\code{"exp"}, \code{"floor"}, \code{"gamma"}, \code{"lgamma"},
\code{"sin"}, \code{"sinh"}, \code{"tan"}, \code{"tanh"},
\code{"trunc"}
\item[\code{Math2}] \code{"round"}, \code{"signif"}
\item[\code{Summary}] \code{"max"}, \code{"min"}, \code{"range"},
\code{"prod"}, \code{"sum"}, \code{"any"}, \code{"all"}
\item[\code{Complex}] \code{"Arg"}, \code{"Conj"}, \code{"Im"},
\code{"Mod"}, \code{"Re"}
}
Functions with the group names exist in the \pkg{methods} package but
should not be called directly.

All the functions in these groups (other than the group generics
themselves) are basic functions in R.  They are not by default S4 generic
functions, and many of them are defined as primitives, meaning that
they do not have formal arguments.  However, you can still define
formal methods for them.  The effect of doing so is to create an S4 generic
function with the appropriate arguments, in the environment where the
method definition is to be stored.  It all works more or less as you
might expect, admittedly via a bit of trickery in the background.\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{\Link{methods}} for methods of non-Internal generic functions.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
methods("Math")
methods("Ops")
methods("Summary")

d.fr <- data.frame(x=1:9, y=rnorm(9))
data.class(1 + d.fr) == "data.frame" ##-- add to d.f. ...
\end{ExampleCode}
\end{Examples}

