Skip to content

[Bug]: view button sends explicit .GlobalEnv lookup to terminal instead of View() only #1846

Open

Description

@Fred-Wu

Area

R terminal or code execution

Bug description

When sending code from workspace using view button, it now sends the following instead of View()

View(get("test", envir = .GlobalEnv, inherits = FALSE), title = "test")

Steps to reproduce

  1. Create a data.frame test <- data.frame(xtest = 1:100L) in R terminal
  2. Click on the view button

Expected behavior

View(test) appears in the terminal.

Environment

Latest development version

Relevant R package versions

No response

Relevant VS Code settings

Logs and additional context

No response

Activity

  1. eitsupi commented on Oct 7, 2026

    @eitsupi
    Member

    I also replied in #1836, but to clarify the background in more detail here:

    This command form is currently intentional, and was introduced by #1805 rather than #1837.

    Before #1805, the Workspace viewer effectively sent:

    View(test)

    #1805 made Workspace actions session-aware and changed root-object viewing to use the exact binding from .GlobalEnv:

    View(get("test", envir = .GlobalEnv, inherits = FALSE), title = "test")

    There are two reasons for this form:

    1. Workspace entries are binding names, and not every valid binding name is a syntactically valid R expression. For example, the current regression tests explicitly cover names such as odd " name.
    2. get(..., envir = .GlobalEnv, inherits = FALSE) makes it explicit that the object shown is exactly the binding represented by the Workspace tree, while title = ... preserves the original object name in the viewer.

    So simply changing this back to View(test) would lose those guarantees.

    #1837 did not introduce this expression. It restored delivery of the existing session-owned Workspace action to explicitly bound third-party terminals such as vscode-R-console, which is why the expression is now visible there again.

    That said, I agree that exposing this relatively verbose implementation detail in the console is not necessarily ideal UX.

    We already have a workspace_view sess IPC method, which is currently used when viewing nested Workspace objects. A possible follow-up improvement would be to route root-object View actions through the same IPC path as well. That would keep the exact .GlobalEnv lookup semantics without sending the generated View(get(...)) expression to the terminal at all.

    I would therefore treat the current behavior as working as designed rather than a regression, but I think this issue can be useful for discussing whether root Workspace View should also use the existing workspace_view IPC path.

    @renkun-ken Any thoughts?

  2. renkun-ken commented on Oct 7, 2026

    @renkun-ken
    Member

    I agree with the history and lookup rationale: #1805 introduced the explicit lookup, and #1837 restored delivery to explicitly bound third-party terminals. Handling arbitrary binding names and preventing fallback outside .GlobalEnv are good reasons to preserve this lookup. Session ownership is a separate guarantee enforced by the execution/request routing.

    I favor using workspace_view consistently for root and nested Workspace objects. The method already accepts an empty path and preserves the root binding's name as the viewer title. That would also avoid exposing the generated expression in the console. The original report is a valid UX concern even though the command change was intentional.

    There are a few behavior changes to account for in that follow-up:

    • Viewer overrides: the IPC handler calls utils::View, whereas the terminal expression resolves View through the session's search path. A user- or console-provided View in .GlobalEnv would therefore be bypassed. We should check whether downstream consoles rely on this.
    • R Interactive presentation: the current root command produces inline rich output for supported objects, whereas workspace_view uses the viewer notification path and opens a viewer panel. I think treating the Workspace button as an inspection action is reasonable, but this is an observable presentation change.
    • Busy, disconnected, and stale sessions: Interactive submissions queue while R is busy, whereas inspection requests reject. sessionRequest currently catches failures, logs them, and returns undefined, so simply removing the root-command branch could make failed clicks appear silent. The follow-up should show an actionable error and preserve validation of the node's originating session, including after reconnect/restart.

    Local validation against the current checkout: the targeted sess list/viewer suite passed all 437 checks. Direct R probes confirmed that root IPC preserves non-syntactic names and titles, rejects lookup outside .GlobalEnv, bypasses a global View override, and emits a viewer notification where the current Interactive command emits inline display output.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions