Repository navigation
Description
System details
RStudio Edition : Desktop [Open Source]
RStudio Version : 2023.12.0.278
OS Version : macOS 13.6
R Version : R version 4.2.0 (2022-04-22)
Steps to reproduce the problem
Any user-defined functions that aren't Sourced will open up a read-only Source Window.
Use the following code in a .R file named single-fn.R and highlight the entire script and Cmd+Enter or click on "Run".
get_index <- function(currIndex){
print(currIndex)
browser()
}
get_index(5)Alternatively, create a second .R file named debug-index.R and also try running it with Cmd+Enter or via "Run". Each time you step through the function it will open/return to the read-only view.
get_index <- function(currIndex){
print(currIndex)
browser()
}
lapply(
X = 1:10,
FUN = get_index
)Describe the problem in detail
Per the docs:
If RStudio can’t find a .R file that matches the function, it will show the code in the Source Viewer. This can happen either because no .R file exists or because the function object doesn’t match the definition in the .R file.
Even if the code for the function hasn't changed AND the source is available it is still opening a read-only view.
Overall I don't think we NEED to open a read-only view unless the function comes from a malformed package or some other location where the source code is not retrievable, unlike the interactive workflow of a local file.
I have seen a few issues that #6740 #9943 and have split off this topic from: #12505 . There's a lot of chatter on a few issues and some emails.
Describe the behavior you expected
If I source() or use the Source button in RStudio, it will keep focus on the sourced open file. I believe that this behavior should be present unless we truly find an externally defined function that the user cannot access. I think this is a regression because the source IS available and at worst, it should return focus to the file where the function exists. As a potential mitigation, perhaps we could allow users to turn off the "read only view".
I think the source for this is:
Lines 760 to 772 in 68a2b9b
| @Override | |
| public void highlightDebugLocation( | |
| SourcePosition startPos, | |
| SourcePosition endPos, | |
| boolean executing) | |
| { | |
| docDisplay_.highlightDebugLocation(startPos, endPos, executing); | |
| if (!shownWarningBar_) | |
| { | |
| view_.showWarningBar(constants_.debugLocationIsApproximate()); | |
| shownWarningBar_ = true; | |
| } | |
| } |
And perhaps we want to follow a heuristic that if the user closes the "Warning bar for approximate location" we should also not open the readonly view?
Lines 224 to 226 in 68a2b9b
| // we only show the warning bar (for debug line matching) once per | |
| // function; don't keep showing it if the user dismisses | |
| shownWarningBar_ = false; |
Steps to reproduce the problem
Describe the problem in detail
Describe the behavior you expected
- I have read the guide for submitting good bug reports.
- I have installed the latest version of RStudio, and confirmed that the issue still persists.
- If I am reporting an RStudio crash, I have included a diagnostics report.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity
[-]Browser opens read only view on execution unless entire function or file is sourced[/-][+]browser() statement opens read only view on execution unless entire function or file is sourced[/+]vertesy commentedon Jan 10, 2024
I encountered the same issue, but I am not sure what the
unlessrefers to.I have a fun that work generally well, but fails on a specific dataset.
Jumping happens if I redefine the same fun as
qSeuViolin2in the current window (saved script) then callqSeuViolin2()Based on the current title of this thread, I tried:
2. I redefined
qSeuViolin3intest.rand thensource(test.R)thenqSeuViolin3()browser()is ignored just fails with error. This was unexpected to me.3. Same ignore happened if I add
browser()to library's code,devtools::load_all(Seurat.Utils)thenqSeuViolin()I use
RStudio 2023.09.1+494.pro2 "Desert Sunflower" Release (80aa7dd, 2023-10-16) for CentOS 7 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0
Is there a workaround? (as I thought from the title)
lachlansimpson commentedon Jan 11, 2024
Seen in ticket #99601
vertesy commentedon Jan 12, 2024
Thanks! Do you have a link, or is it internal?
lachlansimpson commentedon Jan 12, 2024
@vertesy correct, that's to an internal ticket tracker.
wyuill commentedon Jan 19, 2024
We also have this issue with Posit Workbench 2023.09.1+494.pro2, “Desert Sunflower” (80aa7dd)
PatrickCoyle commentedon Feb 21, 2024
I am the submitter of internal ticket #99601. I am experiencing this issue on Posit Workbench 2023.12.0 Build 369.pro3. @datakid and @vertesy thank you for your help!
kevinushey commentedon Mar 2, 2024
If I'm understanding the issue correctly, I think this is expected. RStudio relies on R's source references in order to guide the debugger view, and source references giving the file location can only be available if the associated functions are executed via
source().If they're run in the console via Cmd + Enter or the Run button, then those source references aren't set, and we won't be able to present the "original" view. (Conceptually, this is like copy + pasting the code from the file into the Console pane -- at that point, we no longer know that the code came from that source file.)
The issue described in the internal ticket 99601 sounds different -- if I'm understanding correctly, that's specifically about the IDE focus being forced back into the debugged file every time a command is executed. Is that correct? This sounds very similar to #10664 -- @PatrickCoyle, can you confirm if that issue matches the behavior you're seeing?
PatrickCoyle commentedon Mar 2, 2024
@kevinushey yes that is a correct summary of what I'm seeing (internal ticket #99601). The behavior I see is the same as what's described in #9918, not #10664 or #13925 (although they may be related. I couldn't say). Thank you.
kevinushey commentedon Mar 4, 2024
Thanks @PatrickCoyle -- I think the issue you describe will be fixed via #14360, and that fix will be in the next daily builds for testing (hopefully available by tomorrow).
ronblum commentedon Mar 13, 2024
Verified fixed in RStudio Desktop 2024.04.0-daily+573 on MacOS 14.4, using the original posts examples.