Skip to content

Commit c02ace5

Browse files
PR1706 follow-ups (#1716)
* fix(plot): avoid leaking plot_backend into the global environment profile.R is sourced as the user's R_PROFILE_USER, so the top-level plot_backend assignment created a stray variable in the user's global environment that persisted after startup (reported by @Fred-Wu). Wrap the sess::connect() setup in local() so the temporary plot_backend binding stays scoped, matching the pattern used by the .Rprofile block above it. * feat(plot): warn when a requested plot backend is unavailable When r.plot.backend explicitly selects jgd or httpgd (or the legacy r.plot.useHttpgd is true) but the package is not installed, register_hooks silently fell back to the standard viewer. The standard viewer has no plot-cycling UI, so users saw a degraded experience with no explanation (several reports on #1706). Emit a warning from register_hooks naming the requested backend and the remedy, but only when a specific backend was explicitly requested. The auto mode (use_jgd && use_httpgd) still degrades silently by design.
1 parent 1802ecb commit c02ace5

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

R/profile.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ local({
2525
})
2626

2727
if (requireNamespace("sess", quietly = TRUE)) {
28-
plot_backend <- Sys.getenv("SESS_PLOT_BACKEND", "auto")
29-
sess::connect(
30-
use_rstudioapi = as.logical(Sys.getenv("SESS_RSTUDIOAPI", "TRUE")),
31-
use_httpgd = (plot_backend %in% c("auto", "httpgd")),
32-
use_jgd = (plot_backend %in% c("auto", "jgd"))
33-
)
28+
local({
29+
plot_backend <- Sys.getenv("SESS_PLOT_BACKEND", "auto")
30+
sess::connect(
31+
use_rstudioapi = as.logical(Sys.getenv("SESS_RSTUDIOAPI", "TRUE")),
32+
use_httpgd = (plot_backend %in% c("auto", "httpgd")),
33+
use_jgd = (plot_backend %in% c("auto", "jgd"))
34+
)
35+
})
3436
}

sess/R/hooks.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ register_hooks <- function(use_rstudioapi = TRUE, use_httpgd = TRUE, use_jgd = F
162162
notify_client("httpgd", list(url = httpgd::hgd_url()))
163163
})
164164
} else {
165+
# If a specific interactive backend was explicitly requested but is
166+
# unavailable, warn before silently degrading to the standard viewer.
167+
# (use_jgd && use_httpgd means "auto", which is meant to degrade quietly.)
168+
if (xor(use_jgd, use_httpgd)) {
169+
if (use_jgd && !requireNamespace("jgd", quietly = TRUE)) {
170+
warning("[sess] Plot backend \"jgd\" was requested but the jgd package ",
171+
"is not installed. Falling back to the standard plot viewer. ",
172+
"Install jgd, or change the r.plot.backend setting.", call. = FALSE)
173+
} else if (use_jgd) {
174+
warning("[sess] Plot backend \"jgd\" was requested but no renderer ",
175+
"connection is available. Falling back to the standard plot ",
176+
"viewer.", call. = FALSE)
177+
} else if (use_httpgd) {
178+
warning("[sess] Plot backend \"httpgd\" was requested but the httpgd ",
179+
"package is not installed. Falling back to the standard plot ",
180+
"viewer. Install httpgd, or change the r.plot.backend setting.",
181+
call. = FALSE)
182+
}
183+
}
184+
165185
# Default to static plot capturing (Re-implementation based on legacy plot handler)
166186
plot_file <- .sess_env$latest_plot_path
167187
file.create(plot_file, showWarnings = FALSE)

0 commit comments

Comments
 (0)