Do any R IDEs support conditional breakpoints?
Asked Answered
E

3

15

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.

Ethiopian answered 5/3, 2012 at 5:2 Comment(3)
If you would like to see this feature in RStudio, you could create a feature request on their website. They responded to a few I did, although they only replied it was put on the list of features to be implemented :).Newel
@PaulHiemstra Someone made that request a year ago, so I'll refrain from duplicating feature requests. Ironically, this question ranks highly for web searches on [Rstudio "conditional breakpoints"]. :)Ethiopian
I would create the request anyway, this reminds the people at RStudio that this particular feature is important. There is no way to vote for certain improvements or bugs, so posting the request multiple times is the mechanism to get more attention.Newel
P
9

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:

Predesignate answered 5/3, 2012 at 12:57 Comment(1)
Excellent, thanks! This is a compelling reason for me to try StatET.Ethiopian
S
2

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

Sidonia answered 3/9, 2016 at 13:38 Comment(0)
H
0

The preview release of RStudio v0.98 has this feature: http://www.rstudio.com/ide/docs/debugging/overview

Only drawback is your function should be in the same file with your main code if you want to set a breakpoint in your function.

Hamburg answered 18/10, 2013 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.