Repository navigation
Device capabilities checker - #5350
Conversation
|
@mjskay because you were rooting for a checker in #5299 (comment): do you think the proposed solution will help ggdist/ggblend? I'd be happy to make improvements if needed |
|
Awesome, thanks @teunbrand! I'll try to take a look this week and let you know what I think. Really excited to offload this logic :). |
|
This is great, thanks! Some thoughts:
|
|
Thanks so much for your thoughts @mjskay!
Yeah I struggled with this as well. I think whenever RStudioGD is the active device, the next device is the back-end, but I don't know how well that assumption holds. In any case, that is what the latest changes check for now.
I see your points, and I think they make sense. The goal here was to make a checker that you could throw into an if-statement without any headaches, and returning
Yeah that is a good point. At first I thought I should implement a devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
pdf()
append_warning <- function(expr, append = NULL){
try_fetch(
expr,
warning = function(cnd) {
warn(
message = cnd_message(cnd),
body = cli::format_warning(append),
class = class(cnd),
call = cnd$call
)
invokeRestart("muffleWarning")
}
)
}
append_warning(
check_device("compositing", action = "warn", op = "clear"),
c("*" = "Thou shalt not use this function.")
)
#> Warning: The pdf device does not support 'clear' compositing.
#> • Thou shalt not use this function.
#> [1] FALSECreated on 2023-07-31 with reprex v2.0.2
As a device can potentially support an arbitrary subset of these blending/compositing operations, this seems like a good thing to include. I've included an |
Ah great! FWIW I tested the new version on RStudioGD on a few machines and it worked :). Thanks!
Nice, that should work for my needs and is more elegant :)
Fair. As another suggestion, what about an argument like
Great, thanks! One minor issue with this is that it distinguishes between blending and compositing ops in the check, even though the underlying > ggplot2::check_device("blending", op = "multiply")
[1] TRUE
> ggplot2::check_device("compositing", op = "multiply")
Error in `ggplot2::check_device()`:
! `op` must be one of "clear", "source", "over", "in", "out", "atop", "dest",
"dest.over", "dest.in", "dest.out", "dest.atop", "xor", "add", or "saturate", not
"multiply".
Run `rlang::last_trace()` to see where the error occurred.For my usage, ideally I'd like to be able to just check for support for an op without worrying if it is a blending or a compositing op. Thanks for all the work on this! |
|
Latest changes:
|
|
Thanks so much @mjskay for all the feedback on this PR! |
|
Of course! Thanks for all the hard work and iteration. It's definitely gonna make my life easier :) |
This PR aims to fix #5332.
It resolves a roadblock for #5299 and an exported check utility for testing the capabilities of the graphics device.
A few notes:
FALSEfor patterns and gradients in R 4.1.0 because they can't be vectorised.dev.capabilities(), the guesses remain sketchy. This is particularly the case in R 4.1.0 and even more so for raster devices on Windows platforms.A small demo running this on R 4.2.0, which supports most features but not glyphs. You can use
check_device()in control flow statements whenaction = "test".If
action = "warn"it warns with the likely reason why a feature isn't available:If
action = "error"an error is thrown. Here, because of a version mismatch.Created on 2023-07-13 with reprex v2.0.2