Skip to content

Commit 70a4c0e

Browse files
authored
early exit for null device (#5567)
1 parent b0e7586 commit 70a4c0e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

R/utilities-checks.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ check_inherits <- function(x,
8989
#' either `"blending"` or `"compositing"`. If `NULL` (default), support for
9090
#' all known blending or compositing operations is queried.
9191
#' @param maybe A logical of length 1 determining what the return value should
92-
#' be in case the device capabilities cannot be assessed.
92+
#' be in case the device capabilities cannot be assessed. When the current
93+
#' device is the 'null device', `maybe` is returned.
9394
#' @param call The execution environment of a currently running function, e.g.
9495
#' [`caller_env()`][rlang::caller_env()]. The function will be mentioned in
9596
#' warnings and error messages as the source of the warning or error. See
@@ -186,6 +187,14 @@ check_device = function(feature, action = "warn", op = NULL, maybe = FALSE,
186187

187188
check_bool(maybe, allow_na = TRUE)
188189

190+
# Grab device for checking
191+
dev_cur <- grDevices::dev.cur()
192+
dev_name <- names(dev_cur)
193+
194+
if (dev_name == "null device") {
195+
return(maybe)
196+
}
197+
189198
action <- arg_match0(action, c("test", "warn", "abort"))
190199
action_fun <- switch(
191200
action,
@@ -233,10 +242,6 @@ check_device = function(feature, action = "warn", op = NULL, maybe = FALSE,
233242
return(FALSE)
234243
}
235244

236-
# Grab device for checking
237-
dev_cur <- grDevices::dev.cur()
238-
dev_name <- names(dev_cur)
239-
240245
if (dev_name == "RStudioGD") {
241246
# RStudio opens RStudioGD as the active graphics device, but the back-end
242247
# appears to be the *next* device. Temporarily set the next device as the

man/check_device.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)