diff --git a/Debugging.Rmd b/Debugging.Rmd index d55abf30e..2ec365919 100644 --- a/Debugging.Rmd +++ b/Debugging.Rmd @@ -156,10 +156,11 @@ traceback() #> 1: f(j()) ``` -You can use `rlang::with_abort()` and `rlang::last_trace()` to see the call tree. Here, I think it makes it much easier to see the source of the problem. Look at the last branch of the call tree to see that the error comes from `j()` calling `k()`. +You can set `rlang`'s error handling to be in use with`rlang::global_handle()`, then use `rlang::last_trace()` to see the call tree. Here, I think it makes it much easier to see the source of the problem. Look at the last branch of the call tree to see that the error comes from `j()` calling `k()`. ```{r, error = TRUE} -rlang::with_abort(f(j())) +rlang::global_handle() +f(j()) rlang::last_trace() ``` @@ -312,7 +313,8 @@ options(error = browser); f() options(error = recover); f() options(error = NULL) -rlang::with_abort(f("a")); +rlang::global_handle() +f("a") rlang::last_trace() ``` @@ -436,14 +438,14 @@ There are other ways for a function to fail apart from throwing an error: internal functions used to turn warnings into errors. * A function may generate an unexpected message. You can use - `rlang::with_abort()` to turn these messages into errors: + `rlang::try_fetch()` to turn these messages into errors: ```{r, error = TRUE} f <- function() g() g <- function() message("Hi!") f() - rlang::with_abort(f(), "message") + rlang::try_fetch(f(), message = function(cnd) rlang::abort("Message occured.", parent = cnd)) rlang::last_trace() ```