Skip to contents

Extract code chunks from R Markdown or Quarto file

Usage

extract_code(file)

Arguments

file

Character string of file name for text that includes code chunks. Can be local file or URL.

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/.

Examples

extract_code("https://raw.githubusercontent.com/JeffreyRStevens/flashr/refs/heads/main/README.Rmd")
#>  [1] "knitr::opts_chunk$set("                             
#>  [2] "  collapse = TRUE,"                                 
#>  [3] "  comment = \"#>\","                                
#>  [4] "  fig.path = \"man/figures/README-\","              
#>  [5] "  out.width = \"100%\""                             
#>  [6] ")"                                                  
#>  [7] "install.packages(\"flashr\")"                       
#>  [8] "# install.packages(\"remotes\")"                    
#>  [9] "remotes::install_github(\"JeffreyRStevens/flashr\")"
#> [10] "library(flashr)"                                    
#> [11] "flashcard(\"data_types\")"                          
#> [12] "flashcard(\"data_types\", termsfirst = FALSE)"      
#> [13] "my_deck <- read.csv(\"inst/extdata/operators.csv\")"
#> [14] "head(my_deck)"                                      
#> [15] "flashcard(\"inst/extdata/operators.csv\")"