I have a main R script which does a multiplication using a function called Multiply().
debugSource("C:/Users/R_debug_breakpoint/myFunction.R")
a<-1
b<-2
mult<-Multiply(a,b)
I write Multiply() in a different R script called "myFunction.R"
"myFunction.R" looks like this:
Multiply<-function(a,b){
c<-a+b
e<-a/b
d<-a*b
return(d)
}
If I want to set a breakpoint inside Multiply() function at the line: d<-a*b and enter source mode to see what the value of c,e.
However, when I press Source option in my main.R, the debugger does not halt at the breakpoint I set inside the Muliply function. It just runs all the codes in main.R.
I search this problem in many webpages, and the most close one is How to set a breakpoint in function body in R-studio?
However, I use debugSource here but it still fails.
Another blog about the breakpoint I found out useful is: https://support.rstudio.com/hc/en-us/articles/200534337-Breakpoint-Troubleshooting
It says:In order to hit breakpoints during sourcing, you need to use the special debug sourcing command debugSource included in RStudio. If you are calling source manually on your file, breakpoints will still work, but will not be enabled until after all the code in the file has been executed.
I think this is reason why it doesn't work, but it doesn't mention a work around for it.
Much appreciated if any help from you guys.