Skip to content

Commit

Permalink
early exit for null device (#5567)
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand authored Dec 8, 2023
1 parent b0e7586 commit 70a4c0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions R/utilities-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ check_inherits <- function(x,
#' either `"blending"` or `"compositing"`. If `NULL` (default), support for
#' all known blending or compositing operations is queried.
#' @param maybe A logical of length 1 determining what the return value should
#' be in case the device capabilities cannot be assessed.
#' be in case the device capabilities cannot be assessed. When the current
#' device is the 'null device', `maybe` is returned.
#' @param call The execution environment of a currently running function, e.g.
#' [`caller_env()`][rlang::caller_env()]. The function will be mentioned in
#' warnings and error messages as the source of the warning or error. See
Expand Down Expand Up @@ -186,6 +187,14 @@ check_device = function(feature, action = "warn", op = NULL, maybe = FALSE,

check_bool(maybe, allow_na = TRUE)

# Grab device for checking
dev_cur <- grDevices::dev.cur()
dev_name <- names(dev_cur)

if (dev_name == "null device") {
return(maybe)
}

action <- arg_match0(action, c("test", "warn", "abort"))
action_fun <- switch(
action,
Expand Down Expand Up @@ -233,10 +242,6 @@ check_device = function(feature, action = "warn", op = NULL, maybe = FALSE,
return(FALSE)
}

# Grab device for checking
dev_cur <- grDevices::dev.cur()
dev_name <- names(dev_cur)

if (dev_name == "RStudioGD") {
# RStudio opens RStudioGD as the active graphics device, but the back-end
# appears to be the *next* device. Temporarily set the next device as the
Expand Down
3 changes: 2 additions & 1 deletion man/check_device.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70a4c0e

Please sign in to comment.