From R to Custom PA Component Part 4
This is part 4 of a series of blogs.
Please refer to the other parts that can be found here
In this blog I will be focusing on how to debug in R. This will assist you in debugging your own R but also assist in understanding what is going on at each step of R code.
So I will cover debugging in RGui and in RStudio
So lets look at debugging the function we did in a previous blog. You will need to execute the function as shown below.
You then need enter the debug command and indicate the function name we want to debug. Once you have done this, when we call the function it wll go into debug mode.
You will now see that when we call the function it shows Browse. We can now at every step look at hat variables is defined, the values in each variable.
If you press enter it will step through each line. If you enter ls() it will show you the variables been declared. Whatever variable you would like to see the value for you just type the variable name. Below you can see I went through the whole function, look at variables declared, looked at variable values.
Every time you execute the function it will debug the function, to stop this you must issue the undebug command.
The other way to go into debug mode is to insert the command browser() in your R code. It will then go into debug mode from the line where the browser is located.
So to debug in RStudio is pretty simple, click in the margin by the line you want to stop at, this creates a break point. Then click source. Note to use the debug your script must be saved.
You will then be in debug mode and be able to step through each line.
Hope this helps, part 5 can be found here From R to Custom PA Component Part 5