Skip to content

Instantly share code, notes, and snippets.

@stufield
Created January 23, 2019 14:56
Show Gist options
  • Save stufield/134b0ff9b404d3f853c9f0ad25268068 to your computer and use it in GitHub Desktop.
Save stufield/134b0ff9b404d3f853c9f0ad25268068 to your computer and use it in GitHub Desktop.
Add to `.Rprofile` to enter/exit debugging mode with `rlang::entrace()`
# Set up custom debugging environment
.customCommands <- new.env()
assign("bug", structure("", class = "debugger_class"), envir = .customCommands)
assign("print.debugger_class", function(debugger) {
if ( !identical(as.character(getOption("error")), "rlang::entrace") ) {
options(error = quote(rlang::entrace()),
rlang__backtrace_on_error = "full") # or "collapse"
message(
crayon::green(
cli::symbol$tick,
"debugging is now ON",
cli::symbol$pointer,
"option error set to rlang::entrace()"
)
)
} else {
options(error = NULL)
message(
crayon::red(
cli::symbol$cross,
"debugging is now OFF",
cli::symbol$pointer,
"option error set to NULL"
)
)
}
}, envir = .customCommands)
attach(.customCommands)
rm(.customCommands)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment