Skip to content

Commit

Permalink
Merge pull request carpentries#200 from mawds/commentgenerated
Browse files Browse the repository at this point in the history
Advise users not to edit .md files generated from .Rmd files
  • Loading branch information
rgaiacs authored Jan 30, 2018
2 parents 0e1523e + 682e775 commit 27ead33
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bin/generate_md_episodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ generate_md_episodes <- function() {
## find all the Rmd files, and generate the paths for their respective outputs
src_rmd <- list.files(pattern = "??-*.Rmd$", path = "_episodes_rmd", full.names = TRUE)
dest_md <- file.path("_episodes", gsub("Rmd$", "md", basename(src_rmd)))

## knit the Rmd into markdown
mapply(function(x, y) {
knitr::knit(x, output = y)
}, src_rmd, dest_md)


# Read the generated md files and add comments advising not to edit them
vapply(dest_md, function(y) {
con <- file(y)
mdfile <- readLines(con)
if (mdfile[1] != "---")
stop("Input file does not have a valid header")
mdfile <- append(mdfile, "# Please do not edit this file directly; it is auto generated.", after = 1)
mdfile <- append(mdfile, paste("# Instead, please edit",
basename(y), "in _episodes_rmd/"), after = 2)
writeLines(mdfile, con)
close(con)
return(paste("Warning added to YAML header of", y))
},
character(1))
}

generate_md_episodes()

0 comments on commit 27ead33

Please sign in to comment.