Skip to content
Snippets Groups Projects
Commit 3396ab8e authored by John Blischak's avatar John Blischak
Browse files

Add hook so that output from R Markdown chunks which generate a warning

or an error has the class "error" and appears in red font.

https://github.com/swcarpentry/lesson-example/blob/gh-pages/LAYOUT.md#topics
parent a7c7240a
Branches
Tags
No related merge requests found
......@@ -9,7 +9,7 @@ opts_chunk$set(tidy = FALSE, results = "markup", comment = NA,
fig.align = "center", fig.path = "fig/")
# The hooks below add html tags to the code chunks and their output so that they
# are properly formatted when the site is built with jekyll.
# are properly formatted when the site is built.
hook_in <- function(x, options) {
stringr::str_c("\n\n~~~{.r}\n",
paste0(x, collapse="\n"),
......@@ -22,5 +22,11 @@ hook_out <- function(x, options) {
"\n~~~\n\n")
}
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_out,
error = hook_out, message = hook_out)
hook_error <- function(x, options) {
stringr::str_c("\n\n~~~{.error}\n",
paste0(x, collapse="\n"),
"\n~~~\n\n")
}
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_error,
error = hook_error, message = hook_out)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment