Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do any R IDEs support conditional breakpoints?

Which, if any, R IDEs (e.g. StatET, Revolution R, RStudio, ESS, NppToR, others) support conditional breakpoints?

This is available via bp in the debug package, or via an additional bit of code that invokes browser() based on a condition. However, it can be more efficient to be able to toggle a particular line # and quickly enter a conditional breakpoint for that particular line, without having additional code or console activities.


Note 1. I've searched a bit for these, and it seems that conditional breakpoints are not available in RStudio, and I think the same may be true for StatET. There appears to be support in ESS (see this page), though I'm not yet familiar with ess-tracebug and whether it's easy to use. It also seems that this works only for older versions of ESS; I'm not yet familiar with functionality for more recent versions.


Update 1. I'm selecting an answer (the only one - Andrie's). The question was answerable regarding whether any IDE supports conditional breakpoints, and, fortunately, Andrie has demonstrated that there exists a solution. I remain interested in any other IDEs that support this, though Eclipse is good enough for now. (At the moment, I prefer Rstudio, but this is already in their feature request list.) If anyone has expertise in ESS and can demonstrate that functionality, I'm sure it will benefit others who happen upon this question.

like image 249
Iterator Avatar asked Mar 05 '12 05:03

Iterator


2 Answers

Yes, this is possible with Eclipse + StatET 2.0 in R 2.14-1.

Eclipse supports conditional debugging, and StatET 2.0 supports visual debugging (as long as you have a fairly recent version of R.)

Assuming you know your way around Eclipse, do the following:

  • Start a debugging session in Eclipse (i.e. invoke a Debug configuration, not a Run configuration)
  • Set a breakpoint in your code
  • Open a Debug perspective
  • Run your code

With the debug perspective open, you will have a pane that contains tabs for Variables / Breakpoints. In the breakpoints tab, select your breakpoint, then click the Conditional / Expression tickbox and enter your condition.

enter image description here

In searching for this answer, I found the following pages helpful:

  • Download and install StatET
  • How to start a debugging session in StatET
  • How to set a conditional breakpoint in Eclipse
like image 142
Andrie Avatar answered Sep 23 '22 03:09

Andrie


There is a little trick to set a conditional breakpoint in rstudio:

for(i in 1:10){
  if(i==5){
    print("set the breakpoint at this line by shift+f9")
  }
  i*i
}

The only drawback is you need to add some extra code

like image 37
qjgods Avatar answered Sep 22 '22 03:09

qjgods