Created
April 13, 2022 21:55
-
-
Save topepo/d2c33745c17c345b398e375f17ae5158 to your computer and use it in GitHub Desktop.
extract_code for purl'ing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extract_code <- function(file) { | |
# TODO we could put in an argument for the pattern | |
# or something more sophisticated... | |
target <- tempfile() | |
knitr::purl(file, output = target, quiet = TRUE) | |
code <- readLines(target) | |
code <- gsub("^##.*", "", code) | |
r_file <- gsub("[Rq]md$", "R", file) | |
writeLines(code, r_file) | |
invisible(TRUE) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment