Skip to content

Commit 800268c

Browse files
teunbrandolivroy
andauthored
Simplify check_device() for {ragg}/{svglite} (#5476)
* Replace ragg/svglite checks with version checks * Increment suggested versions * Apply suggestions from code review Co-authored-by: olivroy <[email protected]> --------- Co-authored-by: olivroy <[email protected]>
1 parent 5a61e2e commit 800268c

File tree

2 files changed

+18
-57
lines changed

2 files changed

+18
-57
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ Suggests:
5959
nlme,
6060
profvis,
6161
quantreg,
62-
ragg,
62+
ragg (>= 1.2.6),
6363
RColorBrewer,
6464
rmarkdown,
6565
rpart,
6666
sf (>= 0.7-3),
67-
svglite (>= 1.2.0.9001),
67+
svglite (>= 2.1.2),
6868
testthat (>= 3.1.2),
6969
vdiffr (>= 1.0.6),
7070
xml2

R/utilities-checks.R

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ check_device = function(feature, action = "warn", op = NULL, maybe = FALSE,
247247
dev_name <- names(dev_cur)
248248
}
249249

250+
# {ragg} and {svglite} report capabilities, but need specific version
251+
if (dev_name %in% c("agg_jpeg", "agg_ppm", "agg_png", "agg_tiff")) {
252+
check_installed(
253+
"ragg", version = "1.2.6",
254+
reason = paste0("for checking device support for ", feat_name, ".")
255+
)
256+
}
257+
if (dev_name == "devSVG") {
258+
check_installed(
259+
"svglite", version = "2.1.2",
260+
reason = paste0("for checking device support for ", feat_name, ".")
261+
)
262+
}
263+
250264
# For blending/compositing, maybe test a specific operation
251265
if (!is.null(op) && feature %in% c("blending", "compositing")) {
252266
op <- arg_match0(op, c(.blend_ops, .compo_ops))
@@ -305,34 +319,8 @@ check_device = function(feature, action = "warn", op = NULL, maybe = FALSE,
305319
}
306320
}
307321

308-
# Test {ragg}'s capabilities
309-
if (dev_name %in% c("agg_jpeg", "agg_ppm", "agg_png", "agg_tiff")) {
310-
# We return ragg's version number if not installed, so we can suggest to
311-
# install it.
312-
capable <- switch(
313-
feature,
314-
clippingPaths =, alpha_masks =, gradients =,
315-
patterns = if (is_installed("ragg", version = "1.2.0")) TRUE else "1.2.0",
316-
FALSE
317-
)
318-
if (isTRUE(capable)) {
319-
return(TRUE)
320-
}
321-
if (is.character(capable) && action != "test") {
322-
check_installed(
323-
"ragg", version = capable,
324-
reason = paste0("for graphics support of ", feat_name, ".")
325-
)
326-
}
327-
action_fun(paste0(
328-
"The {.pkg ragg} package's {.field {dev_name}} device does not support ",
329-
"{.emph {feat_name}}."
330-
), call = call)
331-
return(FALSE)
332-
}
333-
334-
# The vdiffr version of the SVG device is known to not support any newer
335-
# features
322+
# If vdiffr has neither confirmed nor denied its capabilities, the feature
323+
# is assumed to be not supported.
336324
if (dev_name == "devSVG_vdiffr") {
337325
action_fun(
338326
"The {.pkg vdiffr} package's device does not support {.emph {feat_name}}.",
@@ -341,33 +329,6 @@ check_device = function(feature, action = "warn", op = NULL, maybe = FALSE,
341329
return(FALSE)
342330
}
343331

344-
# The same logic applies to {svglite} but is tested separately in case
345-
# {ragg} and {svglite} diverge at some point.
346-
if (dev_name == "devSVG") {
347-
# We'll return a version number if not installed so we can suggest it
348-
capable <- switch(
349-
feature,
350-
clippingPaths =, gradients =, alpha_masks =,
351-
patterns = if (is_installed("svglite", version = "2.1.0")) TRUE else "2.1.0",
352-
FALSE
353-
)
354-
355-
if (isTRUE(capable)) {
356-
return(TRUE)
357-
}
358-
if (is.character(capable) && action != "test") {
359-
check_installed(
360-
"svglite", version = capable,
361-
reason = paste0("for graphics support of ", feat_name, ".")
362-
)
363-
}
364-
action_fun(paste0(
365-
"The {.pkg {pkg}} package's {.field {dev_name}} device does not ",
366-
"support {.emph {feat_name}}."), call = call
367-
)
368-
return(FALSE)
369-
}
370-
371332
# Last resort: list of known support prior to R 4.2.0
372333
supported <- c("pdf", "cairo_pdf", "cairo_ps", "svg")
373334
if (feature == "compositing") {

0 commit comments

Comments
 (0)