Skip to content

Instantly share code, notes, and snippets.

@dill
Created September 19, 2012 21:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dill/3752343 to your computer and use it in GitHub Desktop.
Save dill/3752343 to your computer and use it in GitHub Desktop.
watch a directory for changes to .Rmd (knitr+markdown files) and if any change, knit them. Best used with Marked by Brett Terpstra (set it to watch the .md files that knitr will generate).
# watch all .Rmd files in a directory, if any change, knit them
library(knitr)
# use watch from Hadley's testthat package
library(testthat)
watchr<-function(path){
# the path supplied here can just be something like "./"
# taken from auto-test.r
knit_it<-function(added, deleted, modified) {
changed <- normalizePath(c(added, modified))
for(a_file in changed){
knit(a_file)
}
TRUE
}
watch(path,knit_it,".Rmd")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment