To get the buffer name, using the preceding example as a guide, we see
that the name comes afterdebug atand ends just before the#. Since “debug
at” contains nine characters, the buffer name will start at position 10—hence
the 10 in the call,
substr(debugline,10,linenumstart-2)
The end of the buffer name field is atlinenumstart-2, as it is just before
the #, which precedes the start of the line number. The line number compu-
tation is then similar.
Another illustrative example ofedtdbg’s internal code is its use of the
strsplit()function. For example, at one point, it prints out a prompt to
the user:
kbdin <- readline(prompt="enter number(s) of fns you wish to toggle dbg: ")
As you can see, the user’s response is stored inkbdin. It will consist of a
set of numbers separated by spaces, such as this:
145
We need to extract the numbers from the string 145 into an integer
vector. This is done first viastrsplit(), which produces three strings:"1","4",
and"5". Then we callas.integer()to convert from characters to numbers:
tognums <- as.integer(strsplit(kbdin,split=" ")[[1]])
Note that the output ofstrsplit()is an R list, in this case consisting
of one element, which is in turn the vector("1","4","5"). This leads to the
expression[[1]]in the example.
String Manipulation 259