EVOLUTION-MANAGER
Edit File: match.fun.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: Extract a Function Specified by Name</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.fun {base}"><tr><td>match.fun {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract a Function Specified by Name</h2> <h3>Description</h3> <p>When called inside functions that take a function as argument, extract the desired function object while avoiding undesired matching to objects of other types. </p> <h3>Usage</h3> <pre> match.fun(FUN, descend = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>FUN</code></td> <td> <p>item to match as function: a function, symbol or character string. See ‘Details’.</p> </td></tr> <tr valign="top"><td><code>descend</code></td> <td> <p>logical; control whether to search past non-function objects.</p> </td></tr> </table> <h3>Details</h3> <p><code>match.fun</code> is not intended to be used at the top level since it will perform matching in the <em>parent</em> of the caller. </p> <p>If <code>FUN</code> is a function, it is returned. If it is a symbol (for example, enclosed in backquotes) or a character vector of length one, it will be looked up using <code>get</code> in the environment of the parent of the caller. If it is of any other mode, it is attempted first to get the argument to the caller as a symbol (using <code>substitute</code> twice), and if that fails, an error is declared. </p> <p>If <code>descend = TRUE</code>, <code>match.fun</code> will look past non-function objects with the given name; otherwise if <code>FUN</code> points to a non-function object then an error is generated. </p> <p>This is used in base functions such as <code><a href="apply.html">apply</a></code>, <code><a href="lapply.html">lapply</a></code>, <code><a href="outer.html">outer</a></code>, and <code><a href="sweep.html">sweep</a></code>. </p> <h3>Value</h3> <p>A function matching <code>FUN</code> or an error is generated. </p> <h3>Bugs</h3> <p>The <code>descend</code> argument is a bit of misnomer and probably not actually needed by anything. It may go away in the future. </p> <p>It is impossible to fully foolproof this. If one <code>attach</code>es a list or data frame containing a length-one character vector with the same name as a function, it may be used (although namespaces will help). </p> <h3>Author(s)</h3> <p>Peter Dalgaard and Robert Gentleman, based on an earlier version by Jonathan Rougier. </p> <h3>See Also</h3> <p><code><a href="match.arg.html">match.arg</a></code>, <code><a href="get.html">get</a></code> </p> <h3>Examples</h3> <pre> # Same as get("*"): match.fun("*") # Overwrite outer with a vector outer <- 1:5 try(match.fun(outer, descend = FALSE)) #-> Error: not a function match.fun(outer) # finds it anyway is.function(match.fun("outer")) # as well </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>