S-PLUS has a few functions which are helpful for figuring out
where errors are occurring. The function inspect
is an interactive debugger, which allows you to step through
a function and check the values of the variables at each point.
Usually, this will be sufficient to identify a bug, but
inspect has more advanced features as well.
Type inspect(max.power(2,9)) to trace through a call
to max.power with arguments 2 and 9. The inspect
prompt, d> will appear. Type help to see a list
of commands, and objects to see a list of variables defined
in the function.
The main commands you will need are do to advance one
command of the program, step to advance one line of a loop
of a program, and eval to evaluate a variable.
You can advance multiple lines by typing do followed
by the number of lines, and a similar thing works for step.
The difference between do and step is that do
treats a block of commands (for instance, in a loop) as a single
command, while step looks at each command separately.
The command resume ends the debugger after running through the
rest of the program, and quit ends the debugger without
executing any more.