Rev 7002 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{match.fun}\title{Function Verification for ``Function Variables''}\usage{match.fun(FUN, descend = TRUE)}\alias{match.fun}\arguments{\item{FUN}{item to match as function.}\item{descend}{logical; control whether to search past non-functionobjects.}}\description{This function is called inside functions that take a function asargument. It's purpose is to extract the desired function object whileavoiding undesired matching to objects of other types.}\details{\code{match.fun} is not intended to be used at the top levelsince it will perform matching in the \emph{parent} of the caller.It is assumed that \code{FUN} is an argument passed to the caller and isa function or a character string containing the name of a function.Returns an error if no matching function is found. } \details{ If\code{FUN} is a function, it is returned. If it is a symbol or acharacter vector of length one, it will be looked up using \code{get} inthe 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} twice), and if that fails, an error isdeclared.If \code{descend=TRUE}, \code{match.fun} will look pastnon-function objects with the given name; otherwise if \code{FUN}points to a non-function object then an error is generated.This is now used in base functions such as\code{\link{apply}}, \code{\link{lapply}}, \code{\link{outer}},and \code{\link{sweep}}.}\value{A function matching \code{FUN} or an error is generated.}\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 character object with the same nameof a system function, it will be used.}\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}