Re: [R] how to set debug breaks

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Mon 30 Oct 2006 - 21:50:41 GMT

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/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue Oct 31 12:37:43 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 31 Oct 2006 - 02:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.