Skip to content

Commit

Permalink
Polish debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Dec 19, 2018
1 parent e91c345 commit d2335dc
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 103 deletions.
1 change: 0 additions & 1 deletion Conditions.Rmd
Expand Up @@ -2,7 +2,6 @@

```{r, include = FALSE}
source("common.R")
options(rlang_trace_top_env = rlang::current_env())
```

## Introduction
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Expand Up @@ -32,4 +32,5 @@ Imports:
zeallot
Remotes:
hadley/emo,
r-lib/lobstr
r-lib/lobstr, # crashes with released versio
r-lib/rlang # needed for entrace + last_trace()
224 changes: 127 additions & 97 deletions Debugging.Rmd

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Environments.Rmd
Expand Up @@ -811,6 +811,8 @@ There is one last environment we need to explain, the __caller__ environment, ac

To fully understand the caller environment we need to discuss two related concepts: the __call stack__, which is made up of __frames__. Executing a function creates two types of context. You've learned about one already: the execution environment is a child of the function environment, which is determined by where the function was created. There's another type of context created by where the function was called: this is called the call stack.

<!-- HW: mention that this is actually a tree! -->

### Simple call stacks
\indexc{cst()}
\indexc{traceback()}
Expand Down
2 changes: 2 additions & 0 deletions common.R
Expand Up @@ -14,6 +14,8 @@ knitr::opts_chunk$set(
fig.show = "hold"
)

options(rlang_trace_top_env = rlang::current_env())

options(
digits = 3,
str = strOptions(strict.width = "cut")
Expand Down
9 changes: 9 additions & 0 deletions debugging.R
@@ -0,0 +1,9 @@
f <- function(a) g(a)
g <- function(b) h(b)
h <- function(c) i(c)
i <- function(d) {
if (!is.numeric(d)) {
stop("`d` must be numeric", call. = FALSE)
}
d + 10
}
4 changes: 0 additions & 4 deletions exceptions-example.R

This file was deleted.

Binary file added screenshots/debugging/rstudio-error.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/debugging/rstudio-traceback.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshots/traceback-hidden.png
Binary file not shown.
Binary file removed screenshots/traceback-shown.png
Binary file not shown.

0 comments on commit d2335dc

Please sign in to comment.