From 70a4c0ec11b6eb4a6e67cd3ab5fd89df4ef260d7 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:07:39 +0100 Subject: [PATCH] early exit for null device (#5567) --- R/utilities-checks.R | 15 ++++++++++----- man/check_device.Rd | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/utilities-checks.R b/R/utilities-checks.R index 418268a832..db5fee2353 100644 --- a/R/utilities-checks.R +++ b/R/utilities-checks.R @@ -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 @@ -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, @@ -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 diff --git a/man/check_device.Rd b/man/check_device.Rd index cc09a1de67..906d3ce6e9 100644 --- a/man/check_device.Rd +++ b/man/check_device.Rd @@ -33,7 +33,8 @@ either \code{"blending"} or \code{"compositing"}. If \code{NULL} (default), supp all known blending or compositing operations is queried.} \item{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', \code{maybe} is returned.} \item{call}{The execution environment of a currently running function, e.g. \code{\link[rlang:stack]{caller_env()}}. The function will be mentioned in