Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_device(): Early exit for null device #5567

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading