On 16/09/2013 3:05 PM, Hui Du wrote:
Hi All,

I need some help regarding how to set up a breakpoint in debug. For example, I 
have a very simple/naïve function (a useless function just for demo)

f = function()
{
     x = 10;
     len = 100;

     a = 1;
     for(i in 1:len)
     {
         a = a * i;
     }

y = x + a;
y;
}


If I need to debug it, I can run debug(f). After I go into the debugger, if I 
want to skip the loop and stop in the statement y = y + a, directly, how to do 
that? I know R has a function named setBreakpoint but I have never used it 
correctly.

After you have gone into the debugger, it's too late. setBreakpoint works by modifying the body of the function, and the evaluator has already retrieved the body of the function when you enter.

You can set a breakpoint in a function that is not executing from the top level or from the debugger, and it will stop there on the next invocation. The syntax is something like:

setBreakpoint("filename.R#11")

assuming that the spot where you want to stop is line 11 in the source file filename.R where your function came from. (In July at useR 2013 the RStudio folks were demonstrating a GUI that did the same sort of thing.)

It has been requested that setBreakpoint should be able to work on the active function as well as inactive ones, and there is no fundamental reason why that would be impossible, but it is tricky to manipulate expressions in the middle of evaluating them, so that's not in place (yet?).

Duncan Murdoch

Your help is highly appreciated.

HXD

        [[alternative HTML version deleted]]



______________________________________________
[email protected] 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.

______________________________________________
[email protected] 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.

Reply via email to