Since these are no IDEs for R development, this is usually the best one can have.
So, how does one debug a program in R?
The usual answer is: with print.
But the correct answer is: using the browser()function.
The browser() function works as a break point marker.
Just write browser() where a break point is needed and run the program.
When browser() is interpreted, the program hang its execution and a new command line prompt will be provided, Browse[1]>.
This command line allows one to interact with the variables available in the scope where the program is temporary hanged.
This debug command line accepts the following debug commands:
- n: next, advances to the next line, allows step-by-step.
- c: continue, continues the execution, until the program ends or a new browser() function is found.
- traceback(), shows the stack trace function call.
- Q: quit, stop the program execution.
./M6