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, debugonce functions
    • Deter
      • Use libraries such as testthat packages to write unit tests
      • R CMD check
      • testthat::test_check()
      • Write errors for humans
      • Leave access panels
      • Automate your checks
    • Use RStudio built-in debugging infra

R sessions are like crops, not houseplants