Last active
September 4, 2018 11:39
-
-
Save cgpu/98cda7d49ba801e6ad7ad2f6a3d2d964 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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