Created
April 8, 2022 11:22
-
-
Save wviechtb/9762a9caeb34d919d8b5538864b6315e to your computer and use it in GitHub Desktop.
Use color for signals in R
This file contains 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
message("A message") | |
warning("A warning") | |
stop("An error") | |
globalCallingHandlers( | |
message = function(c) { | |
style <- crayon::make_style("white") | |
c$message <- style(c$message) | |
message(c) | |
invokeRestart("muffleMessage") | |
}, | |
warning = function(c) { | |
style <- crayon::make_style("yellow") | |
c$message <- style(c$message) | |
warning(c) | |
invokeRestart("muffleWarning") | |
}, | |
error = function(c) { | |
style <- crayon::make_style("red") | |
c$message <- style(c$message) | |
stop(c) | |
} | |
) | |
message("A message") | |
warning("A warning") | |
stop("An error") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment