| match.fun {base} | R Documentation |
This function is called inside functions that take a function as argument. It's purpose is to extract the desired function object while avoiding undesired matching to objects of other types.
match.fun(FUN, descend = TRUE)
FUN |
item to match as function. |
descend |
logical; control whether to search past non-function objects. |
match.fun is not intended to be used at the top level
since it will perform matching in the parent of the caller.
It is assumed that FUN is an argument passed to the caller and is
a function or a character string containing the name of a function.
Returns an error if no matching function is found.
A function matching FUN or an error is generated.
The descend argument is a bit of misnomer and probably not
actually needed by anything. It may go away in the future.
It is impossible to fully foolproof this. If one attaches a
list or data frame containing a character object with the same name
of a system function, it will be used.
Peter Dalgaard and Robert Gentleman, based on an earlier version by Jonathan Rougier
# Same as get("*"):
match.fun("*")
# Overwrite outer with a vector
outer <- 1:5
match.fun(outer, descend = FALSE) #-> Error: not a function
match.fun(outer) # finds it anyway
is.function(match.fun("outer")) # as well