There are two different ways to run code under the debugger: launching and attaching.
To launch code under the debugger, you must first tell Visual Studio what
script to launch when you press F5. If you have created a new project using
Visual Studio, the file Script.R, which was automatically created for you,
is predefined as the startup script. If you want to launch a different script,
all you need to do is right-click on a script in Solution Explorer and run the
Set As StartUp R Script command:
You can set breakpoints in the startup script before you press F5 to launch the debugger.
Attaching the debugger to the Interactive Window lets you debug code that you are calling from the Interactive Window. This is especially useful when you are testing a function, and calling it repeatedly with different parameter values. There are two ways to attach a debugger to your Interactive Window session:
Attach Debuggercommand under the Session menu:
It’s important to note that if you attach a debugger to your session, you’ll
first need to tell RTVS what code you would like to debug. You do so by running
source command on the files that you want to debug. You can do this by either:
Source R Scriptcommand
Source Selected File(s)command
If you use F5 to start the debugger, RTVS will automatically source the StartUp file on your behalf.
All standard Visual Studio debugger commands work, with a few limitations.
Here’s a screenshot that shows the many debugging windows and features available to you:
After each debugger command, you’ll also see that you are stopped at the
Environment Browser prompt in the R Interactive Window. From there, you can
also issue Environment Browser commands (e.g.,
n for next command, or
Visual Studio Data Tips let you hover over a variable that you want to inspect, and then drill down into the objects within that variable. This lets you inspect variables in-place, while stopped in the debugger, without having to resort to using other windows like the locals window.