Rev 52927 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/match.fun.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2011 R Core Development Team% Distributed under GPL 2 or later\name{match.fun}\alias{match.fun}\title{Extract a Function Specified by Name}\description{When called inside functions that take a function as argument, extractthe desired function object while avoiding undesired matching toobjects of other types.}\usage{match.fun(FUN, descend = TRUE)}\arguments{\item{FUN}{item to match as function: a function, symbol orcharacter string. See \sQuote{Details}.}\item{descend}{logical; control whether to search past non-functionobjects.}}\value{A function matching \code{FUN} or an error is generated.}\details{\code{match.fun} is not intended to be used at the top level since itwill perform matching in the \emph{parent} of the caller.If \code{FUN} is a function, it is returned. If it is a symbol (forexample, enclosed in backquotes) or acharacter vector of length one, it will be looked up using \code{get}in the environment of the parent of the caller. If it is of any othermode, it is attempted first to get the argument to the caller as asymbol (using \code{substitute} twice), and if that fails, an error isdeclared.If \code{descend = TRUE}, \code{match.fun} will look past non-functionobjects with the given name; otherwise if \code{FUN} points to anon-function object then an error is generated.This is used in base functions such as \code{\link{apply}},\code{\link{lapply}}, \code{\link{outer}}, and \code{\link{sweep}}.}\author{Peter Dalgaard and Robert Gentleman, based on an earlier versionby Jonathan Rougier.}\section{Bugs}{The \code{descend} argument is a bit of misnomer and probably notactually needed by anything. It may go away in the future.It is impossible to fully foolproof this. If one \code{attach}es alist or data frame containing a length-one character vector with thesame name as a function, it may be used (although name spaceswill help).}\seealso{\code{\link{match.arg}}, \code{\link{get}}}\examples{# Same as get("*"):match.fun("*")# Overwrite outer with a vectorouter <- 1:5\dontrun{match.fun(outer, descend = FALSE) #-> Error: not a function}match.fun(outer) # finds it anywayis.function(match.fun("outer")) # as well}\keyword{programming}