getFunction
Search Environments for a Function

Description

Search environments for a function object, ignoring variables with non-function values.

Usage

getFunction(name, generic = TRUE, mustFind = TRUE,
            where = topenv(parent.frame()))

Arguments

name a character string that specifies a variable name.
generic This argument is currently ignored.
mustFind a logical value, if a function is not found and the value is TRUE an error is generated. If FALSE and a function is not found NULL is returned.
where an environment that specifies where to start the search.

Details

This function searches the specified environment, its parent environment, and so on, to find a variable with the specified name containing a function. If a variable with this name is found, but its value is not a function, it is ignored and the search continues.
Value
returns a function object, or NULL if the function is not found and mustFind is FALSE.
See Also
get, is.function, parent.env.
Examples
# test mustFind argument
getFunction("nonExistantFunction", mustFind=FALSE) # returns NULL

# find function in global environment xx <- function(x) x+1 identical(getFunction("xx")(1),2)

e1 <- new.env() e2 <- new.env(parent=e1) assign("xx", function(x)x+10, envir=e1) assign("xx", 34, envir=e2) # search for "xx" in e2 (ignoring non-function), # then e1 (finding function) identical(getFunction("xx",where=e2)(1),11)

Package methods version 4.0.0-28
Package Index