Rstudio does not stop at breakpoint
Asked Answered
B

2

12

A few weeks ago I worked with breakpoints in Rstudio. It worked as I expected: stopping at breakpoints.

However, now I need to use it again, I can't get it to work; more specifically: when I set a breakpoint in Rstudio a red dot is appearing next to the code line (see screenshot), but when running the code, it does not stop at the break point.

I created a simple code example for this post to show what I want: run a for loop line for line.screenshot Rstudio

Perhaps I am just not understanding something :) So, could anyone help me with getting these usefull debugging tools in Rstudio to work?

Thanks in advance.

Brunell answered 27/11, 2018 at 14:57 Comment(6)
How are you running the code exactly? Are you sourcing the file?Byelection
I used "run" to run through the for loop. But now I tried "source" and, indeed, the debugging functionality works :) I wasn't so aware of these two options to run code. Any easy explanation on the difference? In any way: thanks for your help!Brunell
Choosing "run" is just like copying and pasting code into the console. You kind of loose track of line numbers and breakpoints that way. You need to source code as a file in order to for the debugger to able to place breakpoints in the code. It's really just a side effect of R being a mostly interpreted language.Byelection
Okay, thanks for the clear explanation.Brunell
I'm getting the same error -- when I run a Shiny App, the breakpoint is not hit, but when I source the helper file directly, then the breakpoint IS hit.Mitzvah
What exactly should I do step by step to stop the code at a breakpoint?Sassan
H
5

Breakpoints also do not work for me on shiny app developed in RStudio, I am using browser() instead of breakpoints, and it works.

see this

M

Hatshepsut answered 12/2, 2020 at 12:0 Comment(0)
F
0

Encountered this exact problem too. Simply restarting R fixes breakpoint for me in half of the cases.
In the other half, more complicated workaround works. Let's say the very first sourced file looks this way:

rm(list = ls())
rm(list = ls(environment(), all.names = TRUE))
# gc()
## clear RStudio output
# cat("\014")

debugSource('src/module1.r')
debugSource('src/libs/module2.r')
debugSource('src/libs/module3.r')
# and all the project modules

# src/module1/run_main
run_main()

The workaround is debugSource() and to keep an extra excessive breakpoint on the run_main() line.
After that, even breakpoints in nested calls started to stop. Unfortunately, means step over that line on every execution. debugSource() is required only in the first file, other files can be can contain just source(). Probably there is some way to bypass the first breakpoint too, but have not found it yet nor entirely figured out what is going on.

Francophobe answered 3/9, 2024 at 0:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.