EVOLUTION-MANAGER
Edit File: groupGeneric.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: S3 Group Generic Functions</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for groupGeneric {base}"><tr><td>groupGeneric {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>S3 Group Generic Functions</h2> <h3>Description</h3> <p>Group generic methods can be defined for four pre-specified groups of functions, <code>Math</code>, <code>Ops</code>, <code>Summary</code> and <code>Complex</code>. (There are no objects of these names in base <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>, but there are in the <span class="pkg">methods</span> package.) </p> <p>A method defined for an individual member of the group takes precedence over a method defined for the group as a whole. </p> <h3>Usage</h3> <pre> ## S3 methods for group generics have prototypes: Math(x, \dots) Ops(e1, e2) Complex(z) Summary(\dots, na.rm = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, z, e1, e2</code></td> <td> <p>objects.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>further arguments passed to methods.</p> </td></tr> <tr valign="top"><td><code>na.rm</code></td> <td> <p>logical: should missing values be removed?</p> </td></tr> </table> <h3>Details</h3> <p>There are four <em>groups</em> for which S3 methods can be written, namely the <code>"Math"</code>, <code>"Ops"</code>, <code>"Summary"</code> and <code>"Complex"</code> groups. These are not <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> objects in base <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>, but methods can be supplied for them and base <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> contains <code><a href="factor.html">factor</a></code>, <code><a href="data.frame.html">data.frame</a></code> and <code><a href="difftime.html">difftime</a></code> methods for the first three groups. (There is also a <code><a href="factor.html">ordered</a></code> method for <code>Ops</code>, <code><a href="DateTimeClasses.html">POSIXt</a></code> and <code><a href="Dates.html">Date</a></code> methods for <code>Math</code> and <code>Ops</code>, <code><a href="numeric_version.html">package_version</a></code> methods for <code>Ops</code> and <code>Summary</code>, as well as a <code><a href="../../stats/html/ts.html">ts</a></code> method for <code>Ops</code> in package <span class="pkg">stats</span>.) </p> <ol> <li><p> Group <code>"Math"</code>: </p> <ul> <li> <p><code>abs</code>, <code>sign</code>, <code>sqrt</code>,<br /> <code>floor</code>, <code>ceiling</code>, <code>trunc</code>,<br /> <code>round</code>, <code>signif</code> </p> </li> <li> <p><code>exp</code>, <code>log</code>, <code>expm1</code>, <code>log1p</code>,<br /> <code>cos</code>, <code>sin</code>, <code>tan</code>,<br /> <code>cospi</code>, <code>sinpi</code>, <code>tanpi</code>,<br /> <code>acos</code>, <code>asin</code>, <code>atan</code> </p> <p><code>cosh</code>, <code>sinh</code>, <code>tanh</code>,<br /> <code>acosh</code>, <code>asinh</code>, <code>atanh</code> </p> </li> <li> <p><code>lgamma</code>, <code>gamma</code>, <code>digamma</code>, <code>trigamma</code> </p> </li> <li> <p><code>cumsum</code>, <code>cumprod</code>, <code>cummax</code>, <code>cummin</code> </p> </li></ul> <p>Members of this group dispatch on <code>x</code>. Most members accept only one argument, but members <code>log</code>, <code>round</code> and <code>signif</code> accept one or two arguments, and <code>trunc</code> accepts one or more. </p> </li> <li><p> Group <code>"Ops"</code>: </p> <ul> <li> <p><code>"+"</code>, <code>"-"</code>, <code>"*"</code>, <code>"/"</code>, <code>"^"</code>, <code>"%%"</code>, <code>"%/%"</code> </p> </li> <li> <p><code>"&"</code>, <code>"|"</code>, <code>"!"</code> </p> </li> <li> <p><code>"=="</code>, <code>"!="</code>, <code>"<"</code>, <code>"<="</code>, <code>">="</code>, <code>">"</code> </p> </li></ul> <p>This group contains both binary and unary operators (<code>+</code>, <code>-</code> and <code>!</code>): when a unary operator is encountered the <code>Ops</code> method is called with one argument and <code>e2</code> is missing. </p> <p>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</code> 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 ‘incompatible methods’: in that case or if no method is found for either argument the internal method is used. </p> <p>Note that the <code><a href="data.frame.html">data.frame</a></code> methods for the comparison (<code>"Compare"</code>: <code>==</code>, <code><</code>, ...) and logic (<code>"Logic"</code>: <code>&</code> <code>|</code> and <code>!</code>) operators return a logical <code><a href="matrix.html">matrix</a></code> instead of a data frame, for convenience and back compatibility. </p> <p>If the members of this group are called as functions, any argument names are removed to ensure that positional matching is always used. </p> </li> <li><p> Group <code>"Summary"</code>: </p> <ul> <li> <p><code>all</code>, <code>any</code> </p> </li> <li> <p><code>sum</code>, <code>prod</code> </p> </li> <li> <p><code>min</code>, <code>max</code> </p> </li> <li> <p><code>range</code> </p> </li></ul> <p>Members of this group dispatch on the first argument supplied. </p> </li> <li><p> Group <code>"Complex"</code>: </p> <ul> <li> <p><code>Arg</code>, <code>Conj</code>, <code>Im</code>, <code>Mod</code>, <code>Re</code> </p> </li></ul> <p>Members of this group dispatch on <code>z</code>. </p> </li></ol> <p>Note that a method will be used for one of these groups or one of its members <em>only</em> if it corresponds to a <code>"class"</code> attribute, as the internal code dispatches on <code><a href="class.html">oldClass</a></code> and not on <code><a href="class.html">class</a></code>. This is for efficiency: having to dispatch on, say, <code>Ops.integer</code> would be too slow. </p> <p>The number of arguments supplied for primitive members of the <code>"Math"</code> group generic methods is not checked prior to dispatch. </p> <p>There is no lazy evaluation of arguments for group-generic functions. </p> <h3>Technical Details</h3> <p>These functions are all primitive and <a href="InternalMethods.html">internal generic</a>. </p> <p>The details of method dispatch and variables such as <code>.Generic</code> are discussed in the help for <code><a href="UseMethod.html">UseMethod</a></code>. There are a few small differences: </p> <ul> <li><p> For the operators of group <code>Ops</code>, the object <code>.Method</code> 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>""</code>.) </p> </li> <li><p> Object <code>.Group</code> records the group used for dispatch (if a specific method is used this is <code>""</code>). </p> </li></ul> <h3>Note</h3> <p>Package <span class="pkg">methods</span> does contain objects with these names, which it has re-used in confusing similar (but different) ways. See the help for that package. </p> <h3>References</h3> <p>Appendix A, <em>Classes and Methods</em> of<br /> Chambers, J. M. and Hastie, T. J. eds (1992) <em>Statistical Models in S.</em> Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="../../utils/html/methods.html">methods</a></code> for methods of non-internal generic functions. </p> <p><a href="../../methods/html/S4groupGeneric.html">S4groupGeneric</a> for group generics for S4 methods. </p> <h3>Examples</h3> <pre> 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 </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>