Skip to content

"Show in Data Viewer" in Remote SSH debug session falls back to utils::View() and fails with X11 is not available #198

Description

@JakobBD

Caveat: AI

I don't fully understand what caused the error, so I used an AI agent to write a workaround.
That agent suggested it was an issue with the debugger and not my setup, so I asked it to write a bug report.
I pasted that below. Hope it still helps - feel free to close the issue otherwise.
(NB: Before asking AI, I tried this fix, but to no avail)

Summary

In a remote SSH debug session (standard Debug R-Package config), clicking Show in Data Viewer on a variable at a breakpoint failed with:

Error in utils::View(val, node$name) : X11 is not available

This appears to happen because the debugger falls back to utils::View() instead of using VS Code’s internal data viewer path.

Environment

  • VS Code Remote SSH session (Linux host, headless / no X11)
  • rdebugger.r-debugger 0.5.6
  • reditorsupport.r 2.8.8
  • R 4.3.2
  • OS client: Windows (debug target is remote Linux)

What I observed

From debugging inside the session:

  • getOption("viewer") was NULL
  • Sys.getenv("TERM_PROGRAM") was "" early in startup
  • In the debug session:
    • is.function(getOption("vsc.dataViewer")) was initially FALSE
    • grep("tools:vscode", search(), value = TRUE) returned "tools:vscode"
    • exists(".First.sys", envir = globalenv()) was TRUE
    • environmentName(environment(utils::View)) was "" (not rebound)
  • vscDebugger appears to do:
viewFunc <- getOption("vsc.dataViewer", NULL)
if (is.null(viewFunc)) {
  viewFunc <- function(val) utils::View(val, node$name)
}
try(viewFunc(val))

So if vsc.dataViewer is unset, it falls back to utils::View(), which needs X11 in this environment.

Workaround that made it work

I added this in ~/.Rprofile for debug sessions:

  • source ~/.vscode-R/init.R
  • explicitly set options(vsc.dataViewer = function(val) tools:vscode::.vsc.view(val, title="debugger"))

After this, Show in Data Viewer worked and opened VS Code’s internal viewer.

Why the agent thinks this is a real integration issue

Even with tools:vscode attached, vsc.dataViewer can still be unset in the debug session, and utils::View may remain non-rebound. In that state, the debugger fallback is not safe for headless remote environments.

Possible fix (unverified suggestion)

Potentially safer fallback logic in the debugger’s R package (showDataViewerRequest):

  1. Use getOption("vsc.dataViewer") if available.
  2. Else, if tools:vscode is attached and .vsc.view exists, call that.
  3. Else, fall back to utils::View() (current behavior).

Pseudo-logic:

viewFunc <- getOption("vsc.dataViewer", NULL)

if (is.null(viewFunc) && "tools:vscode" %in% search()) {
  vsc_env <- as.environment("tools:vscode")
  if (exists(".vsc.view", envir = vsc_env, mode = "function", inherits = FALSE)) {
    viewFunc <- function(val) get(".vsc.view", envir = vsc_env)(val, title = node$name)
  }
}

if (is.null(viewFunc)) {
  viewFunc <- function(val) utils::View(val, node$name)
}

try(viewFunc(val))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions