Learn R Programming

flashr (version 0.2.0)

extract_functions: Extract function calls from character vector of R code

Description

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.

Usage

extract_functions(code, duplicates = TRUE)

Value

Returns character vector of function names without parentheses (e.g., it returns "library" rather than "library()") included in R code.

Arguments

code

Object that contains R code.

duplicates

Logical indicating whether to include duplicates of functions or whether to remove duplicates (default is TRUE, which includes duplicates).

See Also

Other functions for extracting code and functions: build_functions_df(), extract_code()

Examples

Run this code
extract_functions(extract_code(
  "https://raw.githubusercontent.com/JeffreyRStevens/flashr/refs/heads/main/README.Rmd"
))

Run the code above in your browser using DataLab