Skip to content

Instantly share code, notes, and snippets.

@wviechtb
Created April 8, 2022 11:22
Show Gist options
  • Save wviechtb/9762a9caeb34d919d8b5538864b6315e to your computer and use it in GitHub Desktop.
Save wviechtb/9762a9caeb34d919d8b5538864b6315e to your computer and use it in GitHub Desktop.
Use color for signals in R
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