getFunction(name, generic = TRUE, mustFind = TRUE,
where = topenv(parent.frame()))
existsFunction(f, generic=TRUE, where=topenv(parent.frame()))
| 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. |
| 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. |
# 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)