X-Git-Url: https://git.arvados.org/rnaseq-cwl-training.git/blobdiff_plain/3de94867133c1436c6d6dc9ea9565354d5bc2c53..034e9780249bbca6d3b84614c5aecb43dbd5f93d:/bin/chunk-options.R diff --git a/bin/chunk-options.R b/bin/chunk-options.R index df52611..8ac9572 100644 --- a/bin/chunk-options.R +++ b/bin/chunk-options.R @@ -8,31 +8,49 @@ library("knitr") fix_fig_path <- function(pth) file.path("..", pth) -## We use the swc-rmd- prefix for the figures generated by the lssons -## so they can be easily identified and deleted by `make clean`. The + +## 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 ## figures need to be saved in fig/, but when the site is generated, ## the episodes will be one level down. We fix the path using the ## `fig.process` option. + opts_chunk$set(tidy = FALSE, results = "markup", comment = NA, - fig.align = "center", fig.path = "fig/swc-rmd-", - fig.process = fix_fig_path) + fig.align = "center", fig.path = "fig/rmd-", + 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. + hook_in <- function(x, options) { - stringr::str_c("\n\n~~~{.r}\n", + stringr::str_c("\n\n~~~\n", paste0(x, collapse="\n"), - "\n~~~\n{: .source}\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") } hook_error <- function(x, options) { + x <- gsub("\n$", "", x) stringr::str_c("\n\n~~~\n", paste0(x, collapse="\n"), "\n~~~\n{: .error}\n\n")