\HeaderA{debug}{Debug a function}{debug}
\aliasA{undebug}{debug}{undebug}
\keyword{programming}{debug}
\keyword{environment}{debug}
\begin{Description}\relax
Set or unset the debugging flag on a function.
\end{Description}
\begin{Usage}
\begin{verbatim}
debug(fun)
undebug(fun)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{fun}] any interpreted \R{} function.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
When a function flagged for debugging is entered, normal execution
is suspended and the body of function is executed one statement at a time.
A new browser context is initiated for each step (and the previous one
destroyed).
You take the next step by typing carriage return, \code{n} or \code{next}.
You can see the values of variables by typing their names.
Typing \code{c} or \code{cont} causes the debugger to continue to the
end of the function (or loop if within a loop).
You can \code{debug} new functions before you step in to them from inside
the debugger.
Typing \code{Q} quits the current execution and returns you to the
top--level prompt.
Typing \code{where} causes the debugger to print out the current
stack trace (all functions that are active).
If you have variables with names that are identical to the controls
(eg. \code{c} or \code{n} ) then you need to use \code{print(c)} and
\code{print(n)} to evaluate them.

In order to debug S4 methods (see \code{\LinkA{Methods}{Methods}}), you
need to use \code{\LinkA{trace}{trace}}, typically calling \code{\LinkA{browser}{browser}},
e.g., as \\
\code{trace("plot", browser, exit=browser, signature = c("track", "missing"))}
\end{Details}
\begin{SeeAlso}\relax
\code{\LinkA{browser}{browser}}, \code{\LinkA{trace}{trace}};
\code{\LinkA{traceback}{traceback}} to see the stack after an \code{Error: ...}
message; \code{\LinkA{recover}{recover}} for another debugging approach.
\end{SeeAlso}

