Skip to content

Commit 3396ab8

Browse files
committed
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
1 parent a7c7240 commit 3396ab8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tools/chunk-options.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ opts_chunk$set(tidy = FALSE, results = "markup", comment = NA,
99
fig.align = "center", fig.path = "fig/")
1010

1111
# The hooks below add html tags to the code chunks and their output so that they
12-
# are properly formatted when the site is built with jekyll.
12+
# are properly formatted when the site is built.
1313
hook_in <- function(x, options) {
1414
stringr::str_c("\n\n~~~{.r}\n",
1515
paste0(x, collapse="\n"),
@@ -22,5 +22,11 @@ hook_out <- function(x, options) {
2222
"\n~~~\n\n")
2323
}
2424

25-
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_out,
26-
error = hook_out, message = hook_out)
25+
hook_error <- function(x, options) {
26+
stringr::str_c("\n\n~~~{.error}\n",
27+
paste0(x, collapse="\n"),
28+
"\n~~~\n\n")
29+
}
30+
31+
knit_hooks$set(source = hook_in, output = hook_out, warning = hook_error,
32+
error = hook_error, message = hook_out)

0 commit comments

Comments
 (0)