1 # These settings control the behavior of all chunks in the novice R materials.
2 # For example, to generate the lessons with all the output hidden, simply change
3 # `results` from "markup" to "hide".
4 # For more information on available chunk options, see
5 # http://yihui.name/knitr/options#chunk_options
9 fix_fig_path <- function(pth) file.path("..", pth)
11 ## We use the rmd- prefix for the figures generated by the lssons so
12 ## they can be easily identified and deleted by `make clean-rmd`. The
13 ## working directory when the lessons are generated is the root so the
14 ## figures need to be saved in fig/, but when the site is generated,
15 ## the episodes will be one level down. We fix the path using the
16 ## `fig.process` option.
18 opts_chunk$set(tidy = FALSE, results = "markup", comment = NA,
19 fig.align = "center", fig.path = "fig/rmd-",
20 fig.process = fix_fig_path)
22 # The hooks below add html tags to the code chunks and their output so that they
23 # are properly formatted when the site is built.
25 hook_in <- function(x, options) {
26 stringr::str_c("\n\n~~~\n",
27 paste0(x, collapse="\n"),
31 hook_out <- function(x, options) {
32 x <- gsub("\n$", "", x)
33 stringr::str_c("\n\n~~~\n",
34 paste0(x, collapse="\n"),
35 "\n~~~\n{: .output}\n\n")
38 hook_error <- function(x, options) {
39 x <- gsub("\n$", "", x)
40 stringr::str_c("\n\n~~~\n",
41 paste0(x, collapse="\n"),
42 "\n~~~\n{: .error}\n\n")
45 knit_hooks$set(source = hook_in, output = hook_out, warning = hook_error,
46 error = hook_error, message = hook_out)