Unable to get debugger to work - breakpoint vs browser()

Hello, I am a newbie to RStudio and I am having a difficult time engaging the debugger. I have read the documents and it would seem you only need to set a breakpoint and run the app. I expect it to stop at the breakpoint and enable the debugging commands. However they remain disabled and my breakpoint is not being respected by the application. Is there a way to run this in debug mode?

Another solution is to put browser() command directly in code. It'll do the same thing - stop as soon as program reaches the point.

There are more tips in this webinar:
https://www.rstudio.com/resources/videos/debugging-techniques-in-rstudio-amanda-gadrow-june-2018/

3 Likes

Thank you very much, the browser() command works for me! I was thinking this command only applied when running the app in an external (browser) window.

1 Like

I don't use breakpoints much, as most of the functions I'm debugging are small, so debugOnce or debug are usually pretty efficient.

Disclaimers aside, what you're describing should work, with one caveat: You have to run the script with "Source", not by sending it line-by-line to the console, e.g. by highlighting and running. If it's working correctly and you're debugging a function, a red dot will show up to it in the Environment pane.

1 Like