What is going on here? The main point is thatedtdbgsends remote com-
mands to the Vim text editor. For instance, if you are running Vim with a
server name of 168 and you want the cursor in Vim to move to line 12, you
could type this into a terminal (shell) window:
vim --remote-send 12G --servername 168
The effect would be the same as if you had physically typed12Gat the
Vim window. Since12Gis the Vim command to move the cursor to line 12,
that’s what would occur. Consider this call:
paste("vim --remote-send ",cmd," --servername ",vimserver,sep="")
Here,cmdis the string"12G",vimserveris 168 , andpaste()concatenates all
the indicated strings. The argumentsep=""says to use the empty string as
separator in this concatenation—that is, no separation. Thus,paste()returns
the following:
vim --remote-send 12G --servername 168
Another core element in the operation ofedtdbgis that the program
has arranged, via a call to R’ssink()function, to record to the filedbgsink
most output from R’s debugger in your R window. (Theedtdbgutility works
in concert with that debugger.) That information includes the line num-
bers of your positions in your source file as you step through it using R’s
debugger.
The line position information in the debugger output looks like this:
debug at cities.r#16: {
So, there is code inedtdbgto determine the latest line indbgsinkthat
begins with “debug at.” That line is then placed, as a string, in a variable
nameddebugline. The following code then extracts the line number (16 in
the example) and the source filename/Vim buffer name (cities.rhere):
linenumstart <- regexpr("#",debugline) + 1
buffname <- substr(debugline,10,linenumstart-2)
colon <- regexpr(":",debugline)
linenum <- substr(debugline,linenumstart,colon-1)
The call toregexpr()determines where indebuglinethe # character is
located (character 18 in this example). Adding 1 to that gives the position of
the line number withindebugline.
258 Chapter 11