Saturday, November 14, 2026

Props to the browser() Function

I have recently been hunting some very pesky bugs in a complex application written in R and using the Shiny web application framework. The browser() function from the R base package has been a big help. It pauses execution of the application and lets me poke around. I can see the values of local and global variables at the point of interruption, execute lines of code and see the results, and run computations on the side using both variables from the Shiny app and new variables I introduce.

I had previously used browser() while debugging ordinary R applications, but I was unsure whether it would work in a Shiny app. So far, it works just fine. It might be worth noting that I debug the Shiny app from the RStudio Desktop IDE, which provides a handy console in which the browsing occurs. Presumably browser() can also be used while running the app being debugged from other environments (possibly including running from a terminal).