Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 42 lines (33 sloc) 1.58 KB
#!/usr/bin/Rscript --vanilla
# compiles all .Rmd files in _R directory into .md files in Pages directory,
# if the input file is older than the output file.
# run ./knitpages.R to update all knitr files that need to be updated.
KnitPost <- function(input, outfile, figsfolder, cachefolder, base.url="/") {
# this function is a modified version of an example here:
opts_knit$set(base.url = base.url)
fig.path <- paste0(figsfolder, sub(".Rmd$", "", basename(input)), "/")
cache.path <- file.path(cachefolder, sub(".Rmd$", "", basename(input)), "/")
opts_chunk$set(fig.path = fig.path)
opts_chunk$set(cache.path = cache.path)
opts_chunk$set(fig.cap = "center")
knit(input, outfile, envir = parent.frame())
knit_folder <- function(infolder, outfolder, figsfolder, cachefolder) {
for (infile in list.files(infolder, pattern = "*.Rmd", full.names = TRUE)) {
pattern = "\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d\\-"
# folder = ifelse(grepl(pattern, infile), outfolder, "pages")
outfile = paste0(outfolder, "/", sub(".Rmd$", ".md", basename(infile)))
# knit only if the input file is the last one modified
if (!file.exists(outfile) |$mtime >$mtime) {
KnitPost(infile, outfile, figsfolder, cachefolder)
knit_folder("_R", "_posts", "figs/", "_caches/")
#knit_folder("_R/drafts", "_drafts", "figs/drafts/")