The Art of R Programming

(WallPaper) #1

through the code as you single-step through it. For example, consider this
excerpt from our previous browser output:


Browse[2]> n
debug at cities.r#17: n <- length(x)
Browse[2]> n
debug at cities.r#18: i <- x[n]


This is nice, but where are these lines in our code? Most GUI debuggers
for other languages feature a window showing the user’s source code, with a
symbol indicating the next line to be executed. All of the R tools listed at the
start of this section remedy this lack in core R. The Bravingtondebugpackage
creates a separate window for exactly this purpose. The other tools have your
text editor double as that window, thus saving space on your screen com-
pared to usingdebug.
In addition, these tools allow you to set breakpoints and handle other
debugging operations without moving your screen’s cursor from the editor
window to your R execution window. This is convenient and saves typing as
well, greatly enhancing your ability to concentrate on the real task at hand:
finding your bugs.
Let’s consider the cities example again. I opened the GVim text editor
on my source file in conjunction withedtdbg, did some startup foredtdbg, and
then hit the [ (left bracket) key twice to single-step twice through the code.
The resulting GVim window is shown in Figure 13-1.


Figure 13-1: Source window in edtdbg


Debugging 301
Free download pdf