Created
January 23, 2019 14:56
-
-
Save stufield/134b0ff9b404d3f853c9f0ad25268068 to your computer and use it in GitHub Desktop.
Add to `.Rprofile` to enter/exit debugging mode with `rlang::entrace()`
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
# 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