-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknitpost.R
executable file
·32 lines (25 loc) · 1.12 KB
/
knitpost.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/Rscript --vanilla
# Taken and modified from
# http://varianceexplained.org/pages/workflow.html
# compiles all .Rmd files in _R directory into .md files in the _posts
# 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, base.url = '/') {
# this function is a modified version of an example here:
# http://jfisher-usgs.github.com/r/2012/07/03/knitr-jekyll/
knitr::opts_knit$set(base.url = base.url)
knitr::opts_chunk$set(fig.path = '/lessons/images/',
collapse = TRUE)
knitr::knit(input, outfile, envir = parent.frame())
txt <- sub('^published: false', 'published: true',
readLines(outfile))
writeLines(txt, outfile)
}
for (infile in list.files(pattern="*.Rmd", full.names=TRUE, recursive = TRUE)) {
outfile <- paste0(sub("\\.Rmd$", ".md", 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)
}
}