Skip to content

Commit

Permalink
init slides
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonpileggi committed Jun 22, 2022
1 parent 9089068 commit 3334ef7
Show file tree
Hide file tree
Showing 127 changed files with 14,982 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron
173 changes: 173 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

Binary file added img/debugging.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/haystack.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/reprex-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/reprex-why.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/say_do.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,058 changes: 1,058 additions & 0 deletions index.html

Large diffs are not rendered by default.

325 changes: 325 additions & 0 deletions index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
---
title: "Debugging"
author: "Shannon Pileggi"
footer: "[Debugging](https://github.com/shannonpileggi/iterating-well-with-purrr)"
logo: "img/wtf-logo-monograms-border3-transparent-bg-230x230.jpg"
format:
revealjs:
theme: [night, slides.scss]
highlight-style: a11y
transition: fade
slide-number: true
chalkboard: true
editor: visual
execute:
freeze: auto
---

```{r}
library(countdown)
```

```{r font-awesome-color}
# fill for font awesome icons
fa_fill <- "#C7B41D"
```

# Getting started

## Licensing

<br> Workshop materials have been adapted from the 2020 RStudio [What They Forgot To Teach You About R](https://rstats-wtf.github.io/wtf-2020-rsc/) Workshop.
<br> <br> This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/) (CC BY-SA4.0).

## Checklist

<br>

`r fontawesome::fa("check", fill = fa_fill)` R installed?
Pretty recent?

     Current version 4.2.0

`r fontawesome::fa("check", fill = fa_fill)` RStudio installed?

     I'm on 2022.02.3+492

## Additional resources {.smaller}

- WTF Ch 11 *Debugging R code* <br> <https://rstats.wtf/debugging-r-code.html>

- Advanced R Ch 22 *Debugging* <br> <https://adv-r.hadley.nz/debugging.html>

- Jenny Bryan 2020 RStudio Conf Keynote *Object of type closure is not subsettable* <br> <https://github.com/jennybc/debugging#readme>

- Amanda Gadrow 2018 Webinar *Debugging techniques in RStudio* <br> <https://www.rstudio.com/resources/webinars/debugging-techniques-in-rstudio/>

- Jim Hester 2019 *Introduction to debugging in R and RStudio* <br> <https://www.jimhester.com/talk/2019-crug-debugging/>

- Maëlle Salmon 2021 *How to become a better R code detective?* <br> <https://masalmon.eu/2021/07/13/code-detective/>

- Kara Woo 2019 RStudio Conf *Box plots A case study in debugging and perseverance* <br> <https://www.rstudio.com/resources/rstudioconf-2019/box-plots-a-case-study-in-debugging-and-perseverance/>

##

```{r, out.width="20%"}
#| fig.cap: >
#| Artwork by [\@allison_horst](https://twitter.com/allison_horst).
#| fig.alt: >
#| A cartoon of a fuzzy round monster face showing 10 different emotions experienced during the process of debugging code. The
#| progression goes from (1) “I got this” - looking determined and optimistic; (2) “Huh. Really thought that was it.” - looking a bit
#| baffled; (3) “...” - looking up at the ceiling in thought; (4) “Fine. Restarting.” - looking a bit annoyed; (5) “OH WTF.” Looking very
#| frazzled and frustrated; (6) “Zombie meltdown.” - looking like a full meltdown; (7) (blank) - sleeping; (8) “A NEW HOPE!” - a happy
#| looking monster with a lightbulb above; (9) “insert awesome theme song” - looking determined and typing away; (10) “I love coding” -
#| arms raised in victory with a big smile, with confetti falling.
knitr::include_graphics("img/debugging.jpg")
```

::: footer
<https://github.com/allisonhorst/stats-illustrations>
:::

# Troubleshooting

## 1. Search

<br>

- Google *exact* error message

- keyword search on [RStudio community](https://community.rstudio.com/)

- keyword search on [stackoverflow](https://stackoverflow.com/), `[r]` tag

Samantha Csik 2022 R-Ladies St. Louis Workshop *Teach Me How To Google*: [slides](https://samanthacsik.github.io/teach-me-how-to-google/slides/RLadiesSTL-2022-02-22.html#1), [recording](https://youtu.be/93WsFQUuxvA)

## 2. Reset

<br>

::: r-fit-text
Have you tried turning it `OFF` and `ON` again?
:::

. . .

<br>

::: r-fit-text
Restart R, especially when things get weird.
:::

. . .

<br>

- Session -\> Restart R, or

- Ctrl + Shift + F10 (Windows),

- Cmd + Shift + 0 / Cmd + Shift + F10 (Mac)

## 3. Reprex

::: r-fit-text
minimum `repr`oducible `ex`ample
:::

<br>

![](img/reprex-logo.png){fig-align="center"}

<br>

::: center-x
<https://reprex.tidyverse.org/>
:::

::: footer
*make a reprex..... please* by Sharla Gelfand (2021)

slides: <https://make-a-reprex-please.netlify.app/#1>

recording: <https://www.youtube.com/watch?v=G5Nm-GpmrLw>
:::

## minimum

![](img/haystack.PNG){fig-align="center"}

::: footer
Jenny Bryan (2020) *Object of type closure is not subsettable*

<https://github.com/jennybc/debugging>
:::

::: notes
MINIMAL: Don't wring hands and speculate.
Work a small concrete example that reveals, confirms, or eliminates something.
:::

## `repr`oducible `ex`ample

![](img/say_do.PNG){fig-align="center"}

::: footer
Jenny Bryan (2020) *Object of type closure is not subsettable*

<https://github.com/jennybc/debugging>
:::

::: notes
Reproducible example: No reliance on hidden state
:::

## why reprex

![](img/reprex-why.PNG){fig-align="center"}

::: footer
Jenny Bryan (2020) *Object of type closure is not subsettable*

<https://github.com/jennybc/debugging>
:::

## Review #1

<br>


Troubleshooting strategies:

<br>

1. Search

2. Reset

3. Reprex


## Moving on to...

<br>

::: r-fit-text
formal `debugging` techniques.
:::

## Key concepts

<br>

`location` where did the error occur

<br>

`context` why did the error occur

<br>

`non-interactive` vs `interactive`

<br>

debugging `your code` vs `their code`

::: notes
interactive debugging: pause the execution of a function and launch environment where you can interactively explore what's happening
:::

## Set up

<br>

```{r, echo = TRUE, error = TRUE}
f <- function(x) {
x + 1
}
g <- function(x) f(x)
g("a")
```


# Print



## `print()`

```{r, eval=TRUE, echo=TRUE, error=TRUE, `code-line-numbers`="2"}
f <- function(x) {
print(x)
x + 1
}

g <- function(x) f(x)

g("a")
```
. . .
- can assess `location` by where `print` statement is inserted
- can assess `context` by value printed
- `non-interactive` debugging
- good for `your code`
::: notes
Insert numerous print statements to precisely locate the problem, and see the values of important variables.
Print debugging is slow and primitive, but it always works.
Can provide location by inserting print statements in different places, can provide context by seeing values.
:::
## `cat()`
```{r, eval=TRUE, echo=TRUE, error=TRUE, `code-line-numbers`="2-3"}
f <- function(x) {
cat("f()\n")
cat("x =", x, "\n")
x + 1
}
g <- function(x) f(x)
g("a")
```

. . .

- can assess `location` by where `print` statement is inserted

- can assess `context` by value printed

- `non-interactive` debugging

- good for `your code`

::: notes
print is handy to see full object; cat is handy to create smaller messages
:::

# Traceback

# Browser

# Trace

# Special cases

## Warnings

## Piped expressions

## Rmarkdown

## Shiny
7 changes: 7 additions & 0 deletions index_files/libs/clipboard/clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions index_files/libs/quarto-html/popper.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index_files/libs/quarto-html/quarto-html.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3334ef7

Please sign in to comment.