getFunction(name, generic = TRUE, mustFind = 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 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. |
# 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)