Extract function calls from character vector of R code
Source:R/extract_functions.R
extract_functions.Rd
This function finds all of the R functions in a character vector of R code.
For R scripts, first use readLines()
or readr::read_file()
to import
the script into a character vector. For R Markdown or Quarto documents,
first use extract_code()
to find all of the R code in code blocks. The
character vector can then be passed to extract_functions()
to find all of
the functions. By default, all instances of functions are returned. To omit
duplicate functions, set duplicates = FALSE
.
Value
Returns character vector of function names without parentheses (e.g., it returns "library" rather than "library()") included in R code.
Note
This function is adapted from one Yihui Xie posted at https://yihui.org/en/2023/01/func-call/.
See also
Other functions for extracting code and functions:
build_functions_df()
,
extract_code()
Examples
extract_functions(extract_code(
"https://raw.githubusercontent.com/JeffreyRStevens/flashr/refs/heads/main/README.Rmd"
))
#> [1] "set" "install.packages" "install_github" "library"
#> [5] "flashcard" "flashcard" "read.csv" "head"
#> [9] "flashcard"