EVOLUTION-MANAGER
Edit File: match.arg.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: Argument Verification Using Partial Matching</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 match.arg {base}"><tr><td>match.arg {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Argument Verification Using Partial Matching</h2> <h3>Description</h3> <p><code>match.arg</code> matches <code>arg</code> against a table of candidate values as specified by <code>choices</code>, where <code>NULL</code> means to take the first one. </p> <h3>Usage</h3> <pre> match.arg(arg, choices, several.ok = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>arg</code></td> <td> <p>a character vector (of length one unless <code>several.ok</code> is <code>TRUE</code>) or <code>NULL</code>.</p> </td></tr> <tr valign="top"><td><code>choices</code></td> <td> <p>a character vector of candidate values</p> </td></tr> <tr valign="top"><td><code>several.ok</code></td> <td> <p>logical specifying if <code>arg</code> should be allowed to have more than one element.</p> </td></tr> </table> <h3>Details</h3> <p>In the one-argument form <code>match.arg(arg)</code>, the choices are obtained from a default setting for the formal argument <code>arg</code> of the function from which <code>match.arg</code> was called. (Since default argument matching will set <code>arg</code> to <code>choices</code>, this is allowed as an exception to the ‘length one unless <code>several.ok</code> is <code>TRUE</code>’ rule, and returns the first element.) </p> <p>Matching is done using <code><a href="pmatch.html">pmatch</a></code>, so <code>arg</code> may be abbreviated. </p> <h3>Value</h3> <p>The unabbreviated version of the exact or unique partial match if there is one; otherwise, an error is signalled if <code>several.ok</code> is false, as per default. When <code>several.ok</code> is true and more than one element of <code>arg</code> has a match, all unabbreviated versions of matches are returned. </p> <h3>See Also</h3> <p><code><a href="pmatch.html">pmatch</a></code>, <code><a href="match.fun.html">match.fun</a></code>, <code><a href="match.call.html">match.call</a></code>. </p> <h3>Examples</h3> <pre> require(stats) ## Extends the example for 'switch' center <- function(x, type = c("mean", "median", "trimmed")) { type <- match.arg(type) switch(type, mean = mean(x), median = median(x), trimmed = mean(x, trim = .1)) } x <- rcauchy(10) center(x, "t") # Works center(x, "med") # Works try(center(x, "m")) # Error stopifnot(identical(center(x), center(x, "mean")), identical(center(x, NULL), center(x, "mean")) ) ## Allowing more than one match: match.arg(c("gauss", "rect", "ep"), c("gaussian", "epanechnikov", "rectangular", "triangular"), several.ok = TRUE) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>