1 generate_md_episodes <- function() {
3 # avoid ansi color characters from being printed in the output
5 on.exit(options(op), add = TRUE)
6 options(crayon.enabled = FALSE)
7 ## get the Rmd file to process from the command line, and generate the path
8 ## for their respective outputs
9 args <- commandArgs(trailingOnly = TRUE)
10 if (!identical(length(args), 2L)) {
11 stop("input and output file must be passed to the script")
17 ## knit the Rmd into markdown
18 knitr::knit(src_rmd, output = dest_md)
20 # Read the generated md files and add comments advising not to edit them
21 add_no_edit_comment <- function(y) {
23 mdfile <- readLines(con)
24 if (mdfile[1] != "---")
25 stop("Input file does not have a valid header")
28 "# Please do not edit this file directly; it is auto generated.",
33 paste("# Instead, please edit", basename(y), "in _episodes_rmd/"),
36 writeLines(mdfile, con)
38 return(paste("Warning added to YAML header of", y))
41 vapply(dest_md, add_no_edit_comment, character(1))
44 generate_md_episodes()