Rev 42333 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/debug.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{debug}\title{Debug a Function}\usage{debug(fun)undebug(fun)}\alias{debug}\alias{undebug}\arguments{\item{fun}{any interpreted \R function.}}\description{Set or unset the debugging flag on a function.}\details{When a function flagged for debugging is entered, normal executionis suspended and the body of function is executed one statement at atime. A new browser context is initiated for each step (and theprevious one destroyed).At the debug prompt the user can enter commands or \R expressions.The commands are\describe{\item{\code{n}}{(or just return). Advance to the next step.}\item{\code{c}}{continue to the end of the current context: e.g. to theend of the loop if within a loop or to the end of the function.}\item{\code{cont}}{synonym for \code{c}.}\item{\code{where}}{print a stack trace of all active function calls.}\item{\code{Q}}{exit the browser and the current evaluation andreturn to the top-level prompt.}}(Leading and trailing whitespace is ignored, except for return).Anything else entered at the debug prompt is interpreted as an\R expression to be evaluated in the calling environment: inparticular typing an object name will cause the object to be printed,and \code{ls()} lists the objects in the calling frame. (If you wantto look at an object with a name such as \code{n}, print it explicitly.)If a function is defined inside a function, single-step though to theend of its definition, and then call \code{debug} on its name.In order to debug S4 methods (see \code{\link[methods]{Methods}}), youneed to use \code{\link{trace}}, typically calling \code{\link{browser}},e.g., as \cr\code{trace("plot", browser, exit=browser, signature = c("track", "missing"))}}\seealso{\code{\link{browser}}, \code{\link{trace}};\code{\link{traceback}} to see the stack after an \code{Error: \dots}message; \code{\link{recover}} for another debugging approach.}\keyword{programming}\keyword{environment}