I want to step through an R script. I saw the "debug" command while searching for how to do this but that seems to only apply to functions. This script doesn't have any functions.
The "browser" command looked promising so I put "browser()" as the first line of my script but it didn't seem to do anything when I ran it.
How do I get the script to pause on the first line so I can step through it?
In addition to debug() and browser(), you can also enter debug mode by setting “editor breakpoints” in RStudio by clicking to the left of the line in RStudio, or by selecting the line and typing shift+F9.
Ctrl + Enter – Runs the current line and jumps to the next one, or runs the selected part without jumping further. Alt + Enter – Allows running code without moving the cursor to the next line if you want to run one line of code multiple times without selecting it. Ctrl + Alt + R – Runs the entire script.
I was racking my brain trying to figure this out (stepping through a script without a specific function to call) in RStudio's IDE Version 0.98.1102.
Solution for a new script in RStudio:
ctrl+shift+n
)break point
by break point
(red dot) orbrowser()
to the code line where you want to set a break point
Source on Save
box (above the Source
window) and then saving the file,Source
button at the top-right of the Source
window,debugSource("<yourfilename>")
+ enter
in the Console
, orctrl+shift+s
For more steps on debugging in RStudio, see this help file (dated April 23, 2015 12:59).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With