I'm running a script in R (using R Studio) which calls several nested functions (the script calls a function, which has some code, and then calls another function, etc). I need to debug a function which is several levels down. I can get into the first function called by the script by placing a breakpoint on the line with the function call, and then stepping into the function. However, when I try to repeat this step to get into the next function (by having a breakpoint at the line for the next function call), R just keeps running the code until it's done. Even using the 'continue' command which claims "continue execution until the next breakpoint is encountered."
I can get to the other functions by stepping through line by line, and then stepping into each function once I reach it, but it would take a very long time to get where I need to this way.
Any thoughts are appreciated
debug is very convenient for problems of that sort. Say, you want to go through the function myfun step by step. Just run debug(myfun) before you run your code and it will behave as if you had a breakpoint on the first line of that function.
This works also, if the function is called from within other functions or if it is inside a package. In the latter case, it is particularly useful, because you can not just change the code of a function that comes from a package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With