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.
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.
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
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
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.
Related
My goal is to be able to reasonably debug any R-based code, even code from libraries (from install.packages, by placing breakpoints or debug statements (i.e., browser) at any line. I haven't been able to figure out how to reliably edit the source of any library function yet (assuming it is not compiled, e.g., editing a S3 method). However, I put a breakpoint in my main function and then used the debugger to step into the code for the library of interest. In RStudio, the file says "Debug location is approximate because the source is not available." That's fine, but I would like to be able to put additional breakpoints into this "virtual file" so that I don't have to step line by line until I get to the line of interest. Placing these breakpoints does not seem to be possible.
I also can't figure out how to edit the file (which would presumably then support breakpoints). Perhaps I need to install the source locally but it is not clear how to do that. Also, I don't know what the implications of using the source code is. Would I need to manually compile any parts of the library that are actually compiled? My preference would be to have an installation option that allows for editing anything that is interpreted but that doesn't force me to compile everything that the standard installation method typically compiles on its own.
Try:
trace(Fun_name, edit = T)
I often code functions in the following way by creating a basic function, entering debug mode, and then writing the function in debugmode. E.g.,
myfun <- function(x) print(x)
debugonce(myfun)
myfun("test")
The benefits of this is that I can get real time feedback on whether my code is working with the arguments passed to it.
However RStudio appears to have recently changed it's behaviour to make this more difficult. I recently upgraded to 2021.09.0 Build 351.
Previously, it would open the Source Editor when you call this command.
But if you closed this screen, you could return to your code, edit the code, evaluate code, and so on without the viewer re-appering.
However, now it seems to reappear every time you evaluate your code.
For instance, if I close the viewer, go back to my main script, and evaluate x, the Viewer opens back up.
This is super annoying for someone used to editing and evaluating code while in debugmode using the source script file.
Is there any way of entirely disabling the Source Editor view in Rstudio? Or alternatively, is there a way of being able to edit and evaluate code without the Source Editor constantly re-appearing in Rstudio (like how it used to work)?
My current fix is to downgrade to Version 1.3.1093, where you could edit and evaluate code without the Viewer constantly re-appearing. But it would be a shame to miss out on future upgrades.
This issue was principally a bug that has now been fixed.
At time of posting, downloading a daily build fixes the issue, but eventually this fix will be incorporated into beta and standard builds.
https://github.com/rstudio/rstudio/issues/9943
I'm not sure if this is standard behavior for IDEs, but I personally find it irritating. If a file produces warnings when built (unused variables, mismatched ints/longs/etc.), those warnings will cease to be displayed if another file is modified and the "Build project" button is clicked. Doesn't it make more sense for warnings pertaining to unmodified code to continue to be displayed? Is there a way to force this behavior?
The warnings are displayed when the compiler emits them -- unfortunately, that's the design decision taken by both VS team (up to 2008 at least) and by Qt Creator team.
It seems to be standard behavior, and I don't know of any options to override it. It should be easy to fix in Qt Creator, but may be hard to fix in Visual Studio unless relevant APIs are present. For VS you'd need to write an add-in and there would need to be an API available that gives you read-write access to the error list and to the build process. If such APIs exist, then it'd be a simple thing to do as well.
This is "standard behavior", and more specifically, behavior is an attribute of how build systems on Earth "are-designed-to-behave".
As #Kuba notes, the warnings are emitted by the compiler. They aren't stored (except in the "log-of-all-errors/warnings" for the build operation, which the IDE typically never reads-back-and-excerpts-from-for-future-build-operations, which would get their own log of their new warnings/errors). Thus, you won't see the warning again unless the compiler actually compiles the file again, and that's because they would be new warnings that are generated again by the new build operation.
To get what you want (a clever thought, IMHO), the build system would need to:
store warnings from each file-compile (probably on a "per-file-basis")
recall/display those warnings each time that file-output-product was "used"
Very clever. I'm not aware of any system that does that. It would require fairly significant IDE or build-tool-level management of build products, which IMHO, none of them do well (but some are better than others).
This is the year 2012, and not only are we missing our flying cars, but we're missing build systems that merely/quickly build-only-what's-required-using-all-cores while easily handling different configurations. Both were expected by now.
Then, sometime after that, you could probably get your feature. That would be a bonus, because then you could use it in your flying car.
Rstudio has a great code completion feature. It provides a quick view of functions that start with a given string, as well as function and parameter definitions.
ESS is powerful enough, familiar to me, and integrated into Emacs, where I conduct most of my work - so I am hesitant to move, but this feature is making me consider such a move.
Is it possible to integrate this feature into Emacs ESS?
Is there anything similar to this for Emacs ESS?
Any hope that there will be (and if so, how could I support such an effort?)
You do get the completion thanks to the rcompgen package by Deepayan (now "promoted" into base R as part of the utils package). So when I type
lm(
and hit TAB a new buffer opens which gets me the left-hand side of your window above: the available options to the function at hand. I don't think you can show the help directly though.
There is / was also a way to get context-sensitive help in the mini-buffer when typing but I have forgottten how/where that gets turned on.
[EDIT: This is an old answer and auto-complete package dropped out of fashion since then. Please use company-mode instead. It should work by default. Wiki configuration entry is here.]
Recent versions of ESS (> v.12.02) integrate with auto-complete package out of the box (you need not configure anything, just install auto-complete). It provides help on arguments as well as function help. I added detailed instructions to the wiki
Ess-eldoc was also rewritten and from v.12.02 it's active by default, so you don't need to configure anything.
Or maybe we should all use search:
Emacs autocomplete-mode extension for ESS and R
I don't want to be grumpy, I found this few hours ago and I'm still shocked. It works like a charm. Though I still prefer the old-style pop-ups. =)
This is fairly mundane as R questions go, but I would like to specify the font in my R console. It's easy enough to do in Windows - John Cook has an excellent little writeup on that.
However, that is specific for the Windows R GUI. I'm not able to find a way to do this (at least from within R) on RStudio, Linux, etc. Is there a global, platform-agnostic solution? If not, what would need to be wrapped to make this feasible given per-platform idiosyncracies?
Or is this infeasible?
Note that I'm interested in the font family, rather than the font size, though font size suggestions are welcome.
Edit: I plan to apply this inside a program, if possible. Since R can make calls to the shell, I am happy with a two-pass method that first configures external files in preparation for a subsequent invocation of R, if that is necessary.
No, each of the front-ends to R are responsible for the way that the console is displayed to the user. This will be inherently platform and front-end specific.
I believe that Gavin is right: this is set per frontend, and I fail to find anything for Linux. However, the standard R frontend for Windows is addressed in my question. Mac users may find this page helpful: Permanently change default console font.
So, the answers as I found them may be summarized as:
Windows / default R - see John Cook's page
Mac - see link above
Linux / default R frontend - not possible (or am I wrong?)
(Windows, Mac, Linux) / Rstudio - Font family is not available (yet) - see this page. Font size is - this page
Windows / Revolution R - this page
Other / Revolution R - not found
So, the universal trick is that I need to use R via a web server, and then I can configure my browser. :) Not going to happen. I'll wait on Rstudio.