Jennifer Bryan on Debugging
Chanced upon a wonderful presentation by Jennifer Bryan on debugging in R
What does the speaker suggest ?
- Four strategies to debug your code
- Fresh start
- Restart your R-console(Cleans workspace, resets options and environment variables, clears search path)
- Reproducible
- Create a reprex so that you can recreate the bug with a simplified code so that others can help you
- Debug
- Use
traceback(),options(error=recover),browser()options - Comparison to Certificate of Death, Autopsy, War of Crafts Analogy
- Use
debug,debugoncefunctions
- Use
- Deter
- Use libraries such as
testthatpackages to write unit tests R CMD checktestthat::test_check()- Write errors for humans
- Leave access panels
- Automate your checks
- Use libraries such as
- Use
RStudiobuilt-in debugging infra
- Fresh start
R sessions are like crops, not houseplants