while (...) { ... }
Restart early, restart often… and don’t restore data.
There are lots of debugging options in R
for (...)
loops - recapDoing something a fixed number of times:
sequence <- seq(from = 0, to = 2, by = 0.5) for (number in sequence) { print(number) }
[1] 0 [1] 0.5 [1] 1 [1] 1.5 [1] 2
while (...)
loopsDoing something until it is finished:
number <- 0 max.number <- 2 increment <- 0.5 while (number <= max.number) { print(number) number <- number + increment }
[1] 0 [1] 0.5 [1] 1 [1] 1.5 [1] 2
Slide images: Jenny Bryan, https://github.com/jennybc/debugging
Death certificate (modified): Public Domain, https://commons.wikimedia.org/w/index.php?curid=214170
Autopsy painting by Rembrandt: https://www.mauritshuis.nl/en/explore/the-collection/artworks/the-anatomy-lesson-of-dr-nicolaes-tulp-146/detailgegevens/ Public Domain, https://commons.wikimedia.org/w/index.php?curid=64281722
The Night King: https://cnet4.cbsistatic.com/img/vugy5MvUVBvwcJf0JvKIBd1RwJE=/1200x675/2019/04/22/2b2fee8d-111a-4d19-ae83-4e61899cfd47/1nightking.jpg (probably copyright HBO)