diff --git a/screenshots/Amanda_Gadrow.png b/screenshots/Amanda_Gadrow.png new file mode 100644 index 0000000..377ab3a Binary files /dev/null and b/screenshots/Amanda_Gadrow.png differ diff --git a/week4/examples.R b/week4/examples.R index 11e7009..d9d6770 100644 --- a/week4/examples.R +++ b/week4/examples.R @@ -1,3 +1,5 @@ +# Example 1 + f <- function(a) g(a) g <- function(b) h(b) h <- function(c) i(c) @@ -12,8 +14,3 @@ traceback() options(error = recover) f("a") - -f <- function(n = 1e5) { - x <- rep(1, n) - rm(x) -} diff --git a/week4/index.qmd b/week4/index.qmd index 10beded..9332468 100644 --- a/week4/index.qmd +++ b/week4/index.qmd @@ -26,6 +26,10 @@ schedule |> * renv * caching +## Online resources + +* [Amanda Gadrow - Debugging in R](https://posit.co/resources/videos/debugging-techniques-in-rstudio-2/) + ```{r} #| output: asis show_slides(week) diff --git a/week4/slides.qmd b/week4/slides.qmd index e7e6650..838eac3 100644 --- a/week4/slides.qmd +++ b/week4/slides.qmd @@ -13,7 +13,7 @@ format: fig-width: 7.5 fig-height: 3.5 include-in-header: ../header.tex - keep-tex: false + keep-tex: true --- ```{r} @@ -35,6 +35,7 @@ source(here::here("course_info.R")) * Google * Stack Overflow +* Posit Community * Create a minimal reproducible example * Create a unit test * Figure out where the test fails @@ -95,7 +96,11 @@ traceback() * Similar to `browser()` but no change to source code. * Can be set in RStudio by clicking to the left of on the line number, or pressing `Shift + F9`. -* `options(error = recover)` +* `options(error = browser)` + +## Example + +[![Amanda Gadrow -- Debugging in R](../screenshots/Amanda_Gadrow.png)](https://posit.co/resources/videos/debugging-techniques-in-rstudio-2/) ## Interactive debugging @@ -139,15 +144,9 @@ traceback() * `sink()` : capture output to file. * `options(warn = 2)` : turn warnings into errors. * `rlang::with_abort()` : turn messages into errors. -* If R crashes, it is probably a bug in compiled code. +* If R or RStudio crashes, it is probably a bug in compiled code. * Post minimal reproducible example to Posit Community or Stack Overflow. -## Exercise - -Find the problem in the following code - -???? - # Profiling ## Profiling functions