Skip to content

browser() statement opens read only view on execution unless entire function or file is sourced #13925

Closed

Description

@jthomasmock

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)

image

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:

@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?

// 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

  1. added
    new
    on Nov 13, 2023
  2. added this to the milestone on Nov 13, 2023
  3. changed the title [-]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[/+] on Nov 13, 2023
  4. removed this from the milestone on Nov 15, 2023
  5. removed
    new
    on Nov 15, 2023
  6. added this to the Chocolate Cosmos milestone on Nov 20, 2023
  7. vertesy commented on Jan 10, 2024

    @vertesy

    I encountered the same issue, but I am not sure what the unless refers to.

    I have a fun that work generally well, but fails on a specific dataset.

    Jumping happens if I redefine the same fun as qSeuViolin2 in the current window (saved script) then call qSeuViolin2()

    Based on the current title of this thread, I tried:
    2. I redefined qSeuViolin3 in test.r and then source(test.R) then qSeuViolin3() 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) then qSeuViolin()

    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)

  8. lachlansimpson commented on Jan 11, 2024

    @lachlansimpson

    Seen in ticket #99601

  9. vertesy commented on Jan 12, 2024

    @vertesy

    Thanks! Do you have a link, or is it internal?

  10. lachlansimpson commented on Jan 12, 2024

    @lachlansimpson

    @vertesy correct, that's to an internal ticket tracker.

  11. wyuill commented on Jan 19, 2024

    @wyuill

    We also have this issue with Posit Workbench 2023.09.1+494.pro2, “Desert Sunflower” (80aa7dd)

  12. PatrickCoyle commented on Feb 21, 2024

    @PatrickCoyle

    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!

  13. kevinushey commented on Mar 2, 2024

    @kevinushey
    Collaborator

    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?

  14. PatrickCoyle commented on Mar 2, 2024

    @PatrickCoyle

    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?

    @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.

  15. kevinushey commented on Mar 4, 2024

    @kevinushey
    Collaborator

    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).

  16. self-assigned this
    on Mar 5, 2024
  17. self-assigned this
    on Mar 12, 2024
  18. ronblum commented on Mar 13, 2024

    @ronblum
    Contributor

    Verified fixed in RStudio Desktop 2024.04.0-daily+573 on MacOS 14.4, using the original posts examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions