How can you find the names and locations of all the functions that have a specific argument? Is there a way to find them for functions in the global environment, attached packa
I assume that you ask the question just to not lose Ben great answer. Here I slightly modify Ben answer to search for any argument :
uses_arg <- function(x,arg)
is.function(fx <- get(x)) &&
arg %in% names(formals(fx))
For example to get function with na.rm
argument :
basevals <- ls(pos="package:base") ## package name : here I use the base package
basevals[sapply(basevals,uses_arg,'na.rm')]
EDIT
better to name
argument of ls
in conjunction with asNamespace
:
basevals <- ls(asNamespace('base'))
basevals[sapply(basevals,uses_arg,'na.rm')]