# NOT RUN {
## The following should be done within an `rmarkdown` document chunk with
## chunk option `results` set to 'asis' and the chunk option `comment` set
## to ''.
```{r comment="", results='asis', echo=FALSE}
## Change the "output" hook to handle ANSI CSI SGR
old.hooks <- set_knit_hooks(knitr::knit_hooks)
## Do the same with the warning, error, and message, and add styles for
## them (alternatively we could have done output as part of this call too)
styles <- c(
getOption('fansi.style'), # default style
"PRE.fansi CODE {background-color: transparent;}",
"PRE.fansi-error {background-color: #DD5555;}",
"PRE.fansi-warning {background-color: #DDDD55;}",
"PRE.fansi-message {background-color: #EEEEEE;}"
)
old.hooks <- c(
old.hooks,
fansi::set_knit_hooks(
knitr::knit_hooks,
which=c('warning', 'error', 'message'),
style=styles
) )
```
## You may restore old hooks with the following chunk
## Restore Hooks
```{r}
do.call(knitr::knit_hooks$set, old.hooks)
```
# }
Run the code above in your browser using DataCamp Workspace