extract_code: Extract code blocks from R Markdown or Quarto file
Description
To extract code blocks, apply extract_code() to R Markdown or Quarto files
either locally or via a URL. This function returns a character vector where
each line of content from an R code block is an element of the vector. Code
block options are not returned---only the content of the block. Code blocks
from other languages/engines (e.g., Python) are not returned.
Usage
extract_code(file, empty = TRUE, comments = TRUE)
Value
Returns character vector of individual lines of code.
Arguments
file
Character string of file name for text that includes code blocks.
Can be local file or URL.
empty
Logical indicating whether to include empty lines ("") or
whether to remove empty lines (default is TRUE, which includes empty lines).
comments
Logical indicating whether to include comment lines starting
with # or whether to remove comment lines (default is TRUE, which includes
comment lines).
See Also
Other functions for extracting code and functions:
build_functions_df(),
extract_functions()