Skip to content
Prev 103120 / 398500 Next

how to set debug breaks

On Mon, 2006-10-30 at 10:37 -0800, waverley palo wrote:
See ?debug, in particular the use of c to run to the end of the current
context. So you can debug as before, but use c to run through the loop.

Alternatively, see ?browser, which drops you into the debugger wherever
you insert the browser() command, e.g.:

	
foo <- function(n = 10) {
	for(i in 1:n) {
	cat(paste("Doing something #", i, "\r"))
	Sys.sleep(0.5)
	}
	cat("\nFinished loop\n")
	browser()
	X <- runif(100)
	sumX <- sum(X)
	meanX <- mean(X)
	list(sum = sumX, mean = meanX)
}

Will start debugging foo() after the loop has finished.

You might also find Mark Bravington's debug package useful as it
implements further functions for debugging in R

HTH

G