Remove software carpentries logo
[rnaseq-cwl-training.git] / bin / chunk-options.R
index d956f60d0fd7787274c07aee9e9ad1dc5d6fa965..8e0d62af7eed10817d7c3c4d2bc3534a8c2a2b2b 100644 (file)
@@ -20,7 +20,7 @@ knitr_fig_path <- function(prefix) {
     opts_chunk$set(fig.path = new_path)
 }
 
-## We use the rmd- prefix for the figures generated by the lssons so
+## We use the rmd- prefix for the figures generated by the lessons 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,
@@ -29,30 +29,42 @@ knitr_fig_path <- function(prefix) {
 
 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.
 
 hook_in <- function(x, options) {
+  lg <- tolower(options$engine)
+  style <- paste0(".language-", lg)
+
   stringr::str_c("\n\n~~~\n",
-                 paste0(x, collapse="\n"),
-                 "\n~~~\n{: .r}\n\n")
+    paste0(x, collapse="\n"),
+    "\n~~~\n{: ", style, "}\n\n")
 }
 
 hook_out <- function(x, options) {
   x <- gsub("\n$", "", x)
   stringr::str_c("\n\n~~~\n",
-                   paste0(x, collapse="\n"),
-                 "\n~~~\n{: .output}\n\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")
+    paste0(x, collapse="\n"),
+    "\n~~~\n{: .error}\n\n")
+}
+
+hook_warning <- function(x, options) {
+  x <- gsub("\n$", "", x)
+  stringr::str_c("\n\n~~~\n",
+    paste0(x, collapse = "\n"),
+    "\n~~~\n{: .warning}\n\n")
 }
 
-knit_hooks$set(source = hook_in, output = hook_out, warning = hook_error,
-               error = hook_error, message = hook_out)
+knit_hooks$set(source = hook_in, output = hook_out, warning = hook_warning,
+  error = hook_error, message = hook_out)