1 generate_md_episodes <- function() {
3 ## get the Rmd file to process from the command line, and generate the path
4 ## for their respective outputs
5 args <- commandArgs(trailingOnly = TRUE)
6 if (!identical(length(args), 2L)) {
7 stop("input and output file must be passed to the script")
13 ## knit the Rmd into markdown
14 knitr::knit(src_rmd, output = dest_md)
16 # Read the generated md files and add comments advising not to edit them
17 add_no_edit_comment <- function(y) {
19 mdfile <- readLines(con)
20 if (mdfile[1] != "---")
21 stop("Input file does not have a valid header")
24 "# Please do not edit this file directly; it is auto generated.",
29 paste("# Instead, please edit", basename(y), "in _episodes_rmd/"),
32 writeLines(mdfile, con)
34 return(paste("Warning added to YAML header of", y))
37 vapply(dest_md, add_no_edit_comment, character(1))
40 generate_md_episodes()