extract_code {flashr} | R Documentation |
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)
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 ( |
comments |
Logical indicating whether to include comment lines starting
with |
Value
Returns character vector of individual lines of 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_functions()
Examples
extract_code("https://raw.githubusercontent.com/JeffreyRStevens/flashr/refs/heads/main/README.Rmd")