Extract a Function Specified by Name

When called inside functions that take a function as argument, extract the desired function object while avoiding undesired matching to objects of other types.

Usage, descend = TRUE)

item to match as function: a function, symbol or character string. See ‘Details’.


logical; control whether to search past non-function objects.

Details is not intended to be used at the top level since it will perform matching in the parent of the caller.

If FUN 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 get 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 substitute twice), and if that fails, an error is declared.

If descend = TRUE, will look past non-function objects with the given name; otherwise if FUN points to a non-function object then an error is generated.

This is used in base functions such as apply, lapply, outer, and sweep.


A function matching FUN or an error is generated.


The descend argument is a bit of misnomer and probably not actually needed by anything. It may go away in the future.

It is impossible to fully foolproof this. If one attaches 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).

See Also

match.arg, get

library(base) # NOT RUN { # Same as get("*"):"*") # Overwrite outer with a vector outer <- 1:5 try(, descend = FALSE)) #-> Error: not a function # finds it anyway is.function("outer")) # as well # }
Documentation reproduced from package base, version 3.6.2, License: Part of R 3.6.2

Community examples

Looks like there are no examples yet.