R: The debug pane UX outside of debug sessions is confusing
The R debugger works differently than the usual debugging experience in VS Code in that the debug session is initiated by R itself rather than by the frontend. This makes usage very smooth but it also means the contents of the debug pane can be confusing, outside of a debug session. There is a big "Run and debug" button that requests the user to find an appropriate extension, leading them on a wrong path. See for instance https://twitter.com/axiomsofxyz/status/1806582669154869580
We should at least provide a launch.json file to hook that "Run and debug" button to display help about debugger usage.
https://github.com/posit-dev/positron/assets/4465050/58c4a3e1-6fe8-4921-8765-d2ee48dea350
@lionel- thanks for the help! I think this was a new addition recently as it was MIA on the last private beta build?
hmm we've had debug pane support for quite a while. I think if we change the default setting of debug.showInStatusBar to openOnSessionStart this functionality will be much more obvious:
How does debugging actually work? When I try to debug a function, Positron says I need to install an extension. When I try to install the R Debugger extension, it says it cannot be installed due to conflicts with Positron built-in features.
@strengejacke the session debug needs to start with a browser() call. Do not use Debug and Run menu directly. You can see an example here: https://youtu.be/p_4ZS-nnQ2Q?t=53
How do I use this inside packages? I added browser() into the package function where I wanted to debug, then I ran
library(datawizard)
data(efc, package = "datawizard")
dat <- na.omit(efc)
dat$e42dep <- factor(dat$e42dep)
dat$c172code <- factor(dat$c172code)
debugonce(degroup)
degroup(
dat,
select = "c12hour",
by = c("e42dep", "c172code"),
suffix_demean = "_within"
)
And got this screen:
Nevermind, found it out. I just use browser() too seldom.
In R packages with C/C++ code, we should provide a launch configuration for clangd that attaches to the pid of the currently running ark session. This would remove the run and debug button for this specific case.
I am also a bit confused.
I'll use browser() as indicated, but I'm used to breakpoints in RStudio.
I tried all the "breakpoint" menu items in the "run" menu but I couldn't make any of them work, is that intended?
For instance, with an R file opened, I'd hit Run > New breakpoint > Inline breakpoint, and nothing happens, not even an error message.
Are they usable?
Sorry they are not usable yet.
@lionel- no problem, but I think it would be better to hide the UI for features that are not usable. Or at least show an error message telling the user about it. I spent some time clicking again and again without understanding 😅
I find it quite frustrating to debug state inside a function. This is what I miss:
- I can't click in the margin to set a break point
- When I start a "Run and Debug" session I am prompted to install an extension that doesn't come from Positron and I don't know if I can trust
- If I set a browser() breakpoint:
- The debug buttons are small and not very noticable
- I don't see my variable values in the variables pande
- I see my variables listed in in the local variables pane, but I can't inspect
- I am then forced to use old-fashioned print statements to inspect state
- When I search the Positron docs for debugging I get some pages about Python but nothing for R.
Thank you for these comments, @andrie! I added a link to your comment to a few issues we have on more full debugger support.
I think one thing we need to track in this issue is what you highlight here:
When I start a "Run and Debug" session I am prompted to install an extension that doesn't come from Positron and I don't know if I can trust
We need to not have this happen.
In terms of the debugging UI itself, we don't currently have near-term plans to replace or change that, or to use the main Positron variables pane instead of the VS Code debug variables UI.