Merge pull request #345 from maxim-belkin/margin0
[rnaseq-cwl-training.git] / bin / chunk-options.R
index 5836973226adfab41d0423143aa0cccc09317c43..8ac95729372ae9cf1ddb8a4aa32ee1cc608ec84d 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
@@ -17,7 +29,9 @@ fix_fig_path <- function(pth) file.path("..", pth)
 
 opts_chunk$set(tidy = FALSE, results = "markup", comment = NA,
                fig.align = "center", fig.path = "fig/rmd-",
-               fig.process = fix_fig_path)
+               fig.process = fix_fig_path,
+               fig.width = 8.5, fig.height = 8.5,
+               fig.retina = 2)
 
 # The hooks below add html tags to the code chunks and their output so that they
 # are properly formatted when the site is built.
@@ -25,13 +39,13 @@ opts_chunk$set(tidy = FALSE, results = "markup", comment = NA,
 hook_in <- function(x, options) {
   stringr::str_c("\n\n~~~\n",
                  paste0(x, collapse="\n"),
-                 "\n~~~\n{: .r}\n\n")
+                 "\n~~~\n{: .language-r}\n\n")
 }
 
 hook_out <- function(x, options) {
   x <- gsub("\n$", "", x)
   stringr::str_c("\n\n~~~\n",
-                   paste0(x, collapse="\n"),
+                 paste0(x, collapse="\n"),
                  "\n~~~\n{: .output}\n\n")
 }