Non-interactive debugging

When you can’t explore interactively…

callr::r()

callr::r(f, list(1, 2)) calls f(1, 2) in a fresh session to help diagnose:

  • Is the global environment different? Have you loaded different packages? Are objects left from previous sessions causing differences?

  • Is the working directory different?

  • Is the PATH environment variable different?

  • Is the R_LIBS environment variable different?

dump.frames()

dump.frames() is the equivalent to recover() for non-interactive code.

RMarkdown

  • If you’re knitting the file using RStudio, switch to calling rmarkdown::render("path/to/file.Rmd") instead to run the code in the current session.

  • For interactive debugging, you’ll need to call sink() in the error handler. For example, to use recover() with RMarkdown, you’d put the following code in your setup block: