Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Debugging.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```

Expand Down Expand Up @@ -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()
```

Expand Down Expand Up @@ -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()
```

Expand Down