Skip to content

Instantly share code, notes, and snippets.

@randy3k
Last active April 4, 2017 14:35
Show Gist options
  • Select an option

  • Save randy3k/6d94e78115c666d5692a3a34ef60023a to your computer and use it in GitHub Desktop.

Select an option

Save randy3k/6d94e78115c666d5692a3a34ef60023a to your computer and use it in GitHub Desktop.
#!/usr/bin/Rscript --vanilla
# from https://github.com/muuankarski/blog
# run ./knitpages.R to update all Rmd files that need to be updated.
KnitPost <- function(input, outfile) {
require(knitr);
opts_knit$set(base.dir = "content")
opts_knit$set(base.url = "/")
fig.path <- paste0("images/", sub(".Rmd$", "", basename(input)), "/")
opts_chunk$set(fig.path = fig.path)
opts_chunk$set(fig.cap = "center")
knit(input, outfile, envir = parent.frame())
}
for (infile in list.files("content", pattern = "*.Rmd", full.names = TRUE)) {
outfile <- paste0("content/rmd/", sub(".Rmd$", ".md", basename(infile)))
# knit only if the input file is the last one modified
if (!file.exists(outfile) |
file.info(infile)$mtime > file.info(outfile)$mtime) {
KnitPost(infile, outfile)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment