add function knitr_fig_path
authorFrancois Michonneau <francois.michonneau@gmail.com>
Fri, 1 Jul 2016 18:08:58 +0000 (14:08 -0400)
committerFrancois Michonneau <francois.michonneau@gmail.com>
Fri, 1 Jul 2016 18:08:58 +0000 (14:08 -0400)
bin/chunk-options.R

index 5836973226adfab41d0423143aa0cccc09317c43..d956f60d0fd7787274c07aee9e9ad1dc5d6fa965 100644 (file)
@@ -8,6 +8,18 @@ library("knitr")
 
 fix_fig_path <- function(pth) file.path("..", pth)
 
+
+## We set the path for the figures globally below, so if we want to
+## customize it for individual episodes, we can append a prefix to the
+## global path. For instance, if we call knitr_fig_path("01-") in the
+## first episode of the lesson, it will generate the figures in
+## `fig/rmd-01-`
+knitr_fig_path <- function(prefix) {
+    new_path <- paste0(opts_chunk$get("fig.path"),
+                      prefix)
+    opts_chunk$set(fig.path = new_path)
+}
+
 ## We use the rmd- prefix for the figures generated by the lssons so
 ## they can be easily identified and deleted by `make clean-rmd`.  The
 ## working directory when the lessons are generated is the root so the