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):
- Use
getOption("vsc.dataViewer") if available.
- Else, if
tools:vscode is attached and .vsc.view exists, call that.
- 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))
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-Packageconfig), clicking Show in Data Viewer on a variable at a breakpoint failed with:Error in utils::View(val, node$name) : X11 is not availableThis appears to happen because the debugger falls back to
utils::View()instead of using VS Code’s internal data viewer path.Environment
rdebugger.r-debugger0.5.6reditorsupport.r2.8.8What I observed
From debugging inside the session:
getOption("viewer")wasNULLSys.getenv("TERM_PROGRAM")was""early in startupis.function(getOption("vsc.dataViewer"))was initiallyFALSEgrep("tools:vscode", search(), value = TRUE)returned"tools:vscode"exists(".First.sys", envir = globalenv())wasTRUEenvironmentName(environment(utils::View))was""(not rebound)vscDebuggerappears to do: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
~/.Rprofilefor debug sessions:~/.vscode-R/init.Roptions(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:vscodeattached,vsc.dataViewercan still be unset in the debug session, andutils::Viewmay 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):getOption("vsc.dataViewer")if available.tools:vscodeis attached and.vsc.viewexists, call that.utils::View()(current behavior).Pseudo-logic: