This is a flexible function that matches function component against
a regular expression, returning the name of the function if there are any
matches. fun_args and fun_calls are helper functions that
make it possible to search for functions with specified argument names, or
which call certain functions.
find_funs(env = parent.frame(), extract, pattern, ...)
fun_calls(f)
fun_args(f)
fun_body(f)environment in which to search for functions
component of function to extract. Should be a function that
takes a function as input as returns a character vector as output,
like fun_calls or fun_args.
stringr regular expression to results of extract
function.
other arguments passed on to grepl
function to extract information from
find_funs("package:base", fun_calls, "match.fun", fixed = TRUE)
#> Using environment package:base
#> [1] "Filter" "Find" "Map" "Negate" "Position" "Reduce"
#> [7] "apply" "eapply" "lapply" "mapply" "outer" "sapply"
#> [13] "sweep" "tapply" "vapply"
find_funs("package:stats", fun_args, "^[A-Z]+$")
#> Using environment package:stats
#> [1] "SSfpl" "SSmicmen" "addmargins"
#> [4] "aggregate.data.frame" "aggregate.ts" "ave"
#> [7] "chisq.test" "cov2cor" "dendrapply"
#> [10] "fisher.test" "poisson.test" "psmirnov"
#> [13] "qsmirnov"
fun_calls(match.call)
#> [1] "{" "if" "&&" "!" "missing"
#> [6] "is.null" "<-" "sys.function" "sys.parent" ".Internal"
fun_calls(write.csv)
#> [1] "{" "<-" "match.call" "for" "c"
#> [6] "if" "!" "is.null" "[[" "warning"
#> [11] "gettextf" "eval.parent" "$" "&&" "is.logical"
#> [16] "quote" "::"
fun_body(write.csv)
#> [1] "{"
#> [2] " Call <- match.call(expand.dots = TRUE)"
#> [3] " for (argname in c(\"append\", \"col.names\", \"sep\", \"dec\", \"qmethod\")) if (!is.null(Call[[argname]])) "
#> [4] " warning(gettextf(\"attempt to set '%s' ignored\", argname), "
#> [5] " domain = NA)"
#> [6] " rn <- eval.parent(Call$row.names)"
#> [7] " Call$append <- NULL"
#> [8] " Call$col.names <- if (is.logical(rn) && !rn) "
#> [9] " TRUE"
#> [10] " else NA"
#> [11] " Call$sep <- \",\""
#> [12] " Call$dec <- \".\""
#> [13] " Call$qmethod <- \"double\""
#> [14] " Call[[1L]] <- quote(utils::write.table)"
#> [15] " eval.parent(Call)"
#> [16] "}"
find_funs("package:utils", fun_body, "write", fixed = TRUE)
#> Using environment package:utils
#> [1] "RShowDoc"
#> [2] "Rtangle"
#> [3] "RtangleSetup"
#> [4] "RweaveLatex"
#> [5] "Sweave"
#> [6] "aspell"
#> [7] "aspell_write_personal_dictionary_file"
#> [8] "bug.report"
#> [9] "data"
#> [10] "file.edit"
#> [11] "help.start"
#> [12] "history"
#> [13] "install.packages"
#> [14] "make.packages.html"
#> [15] "mirror2html"
#> [16] "package.skeleton"
#> [17] "rtags"
#> [18] "tar"
#> [19] "unzip"
#> [20] "write.csv"
#> [21] "write.csv2"
#> [22] "write.socket"
#> [23] "write.table"