getFunction
Search Environments for a Function

Description

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

Usage

getFunction(name, generic = TRUE, mustFind = TRUE,
            where = topenv(parent.frame()))
existsFunction(f, generic=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 TRUE (the default) and no function is found, the call generates an error. If FALSE and no function is found, the call returns NULL.
where an environment that specifies where to start the search.
f a character string that specifies a variable name.

Details

Value

getFunctionreturns a function object; otherwise it returns NULL if the function is not found and mustFind is FALSE.
existsFunctionreturns TRUE if a suitable function is found; otherwise it returns 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 existsFunction("xx") 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) existsFunction("xx", where=e2)

Package methods version 6.1.4-13
Package Index