Skip to content

Instantly share code, notes, and snippets.

@cgpu
Last active September 4, 2018 11:39
Show Gist options
  • Save cgpu/98cda7d49ba801e6ad7ad2f6a3d2d964 to your computer and use it in GitHub Desktop.
Save cgpu/98cda7d49ba801e6ad7ad2f6a3d2d964 to your computer and use it in GitHub Desktop.
# Highlighting errors, warnings, messages
Color code what R tells you when you need to knw something about your code.
This cool snippet found here: https://selbydavid.com/2017/06/18/rmarkdown-alerts/<br>
Kuddos to [David](https://twitter.com/TeaStats) for sharing!
```{r echo=FALSE}
# Cool snippet for color coding errors
knitr::knit_hooks$set(
error = function(x, options) {
paste('\n\n<div class="alert alert-danger">',
gsub('##', '\n', gsub('^##\ Error', '**Error**', x)),
'</div>', sep = '\n')
},
warning = function(x, options) {
paste('\n\n<div class="alert alert-warning">',
gsub('##', '\n', gsub('^##\ Warning:', '**Warning**', x)),
'</div>', sep = '\n')
},
message = function(x, options) {
paste('\n\n<div class="alert alert-info">',
gsub('##', '\n', x),
'</div>', sep = '\n')
}
)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment