[R] how to set debug breaks

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Oct 30 22:50:41 CET 2006


On Mon, 2006-10-30 at 10:37 -0800, waverley palo wrote:
> Hi,
> 
> I am new in R and have some frustrations as how to set debug breaks during
> emacs R debug.  I use debug () as where or which function to debug.  But
> during the debug, e.g., I have a for loop at the beginning of the function
> code and want the code execution to jump through that for loop and set a
> break after that.  How to do that?  Is there a web site detailing the syntax
> of the debugging of R?  Hopefully it would be similar to java or C syntax.

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

> Thanks.
> 
> waverley

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC & ENSIS, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/cv/
 London, UK. WC1E 6BT.         [w] http://www.ucl.ac.uk/~ucfagls/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list