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

- getFunction 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.
- existsFunction performs the same search, returning TRUE if a suitable function is found. If a suitable function is not found, it returns FALSE.

Value

getFunction | returns a function object; otherwise it returns NULL if the function is not found and mustFind is FALSE.

existsFunction | returns 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.5-18
Package Index