-
Notifications
You must be signed in to change notification settings - Fork 337
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
Record example plots with 'png()' if requested #2314
Conversation
* If `grDevices::png()` is requested in `_pkgdown.yml` use it to record example plots instead of `ragg::agg_png()`. * In particular examples with if blocks using `grDevices::dev.capabilities()` to ensure that a required graphics feature is supported by the active graphics device will now work correctly. fixes #2299
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting to think about this.
As well as the comment about the code, does this need changes to the documentation or tests?
@@ -14,8 +14,14 @@ highlight_examples <- function(code, topic, env = globalenv()) { | |||
|
|||
# some options from testthat::local_reproducible_output() | |||
# https://github.com/r-lib/testthat/blob/47935141d430e002070a95dd8af6dbf70def0994/R/local.R#L86 | |||
if (any(fig_settings()$dev %in% c("png", "grDevices::png"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a confusing interface, because it seems to imply that you can use any graphics device, but only png will work.
Not entirely sure if you want to explicitly test this but here is an example that should show a blue oval if recorded and plotted with # Should draw a blue oval if device supports affine transformation feature
if (getRversion() >= '4.2.0' &&
isTRUE(grDevices::dev.capabilities()$transformations) &&
require("grid")) {
define <- defineGrob(circleGrob(gp = gpar(col = NA, fill = "blue")),
vp = viewport(width = unit(1, "in"), height = unit(1, "in")))
grid.draw(define)
grid.use(define$name, vp = viewport(width = unit(2, "in"), height = unit(1, "in")))
} |
Any movement on this? I'd be happy to take up the mantle of this PR if needed. It currently affects multiple packages I maintain (ggdist, ggblend) where documentation can't be rendered correctly by pkgdown because ragg does not support all modern {grid} features. I'll second @trevorld that I'm not sure anything other than png really needs to be supported here (or maybe png and svg), and note that the existing interface is already confusing in that passing anything other than "ragg" seems to silently still use ragg. I think it would be worth a note in documentation about how this parameter doesn't work as you would expect it to if coming from rmarkdown. |
@mjskay No updates, but I hope to turn my attention towards pkgdown in the not too distant future. But what features is ragg missing? I don't see any open issues in ragg that suggest there's big chunks missing, and I had thought we were up to date with base R features. |
Introduced in R 4.2:
Introduced in R 4.3
I think I recall a mention from the ragg maintainer a while ago that they were planning on supporting the R 4.2 features but were having difficulties with finalizing the compositing operator feature? |
In my case my packages |
@trevorld could you please file that as an issue on ragg? |
If the problem occurs not in the final rendering (which I understand already uses the requested device?), but only when the plot is recorded, would a simpler solution be to always record the plot using a device that will generally have the widest feature support --- e.g. svg or cairo png? |
I believe you can build R without Cairo support and I think |
Do you have some time to think/talk about this this week? If so, we should be able to get something into the upcoming patch release. To me, the main question is what the interface should look like. I think you proposal suggests an interface more broad than what we want to support, and something more like |
Here is a recap of my understanding of the current situation and this PR:
figures:
dev: grDevices::png
dev.args:
type: "cairo" will render (but not record) with the base Cairo png device instead of
|
Oh I didn't realise that the problem was only with recording. In that case, is it possible to take a more general approach and just record and replay with the same device? That is what I'd expect. |
This would be best if "easy". Things that may or may not be "easy":
I asked about these in an earlier comment in this PR... |
I think we could error if there are multiple devices supplied, or simply consider that out of scope. |
FWIW I have been using I agree that just recording with the correct device would be nice. |
I got some urgent work for today but I should be able to update my PR later this week. |
Looks like |
So the code might look something like this (untested): settings <- fig_settings()
dev <- match_fun(settings$dev %||% ragg::agg_png)
settings$dev <- NULL
device <- function(...) {
args <- modify_list(settings, list(...))
do.call(dev, args)
} Hmmmm, that's not quite right because the |
|
Oh yeah, I meant I think the main advantage of setting I'd prefer to not filter out arguments based on |
Just a small data point - ragg with support for all the graphic engine features will land on CRAN in a few days... There may still be good reasons to use other graphics devices so maybe this PR is still relevant, but the original issue should disappear very soon |
@hadley let me know if you'd still like me to work on this PR. I'm okay if it gets closed due to the recent |
If the latest version of ragg fixes your problem, I'm happy to close this PR since it's less work for me 😁 |
If
grDevices::png()
is requested in_pkgdown.yml
use it to record example plots instead ofragg::agg_png()
.In particular examples with if blocks using
grDevices::dev.capabilities()
to ensure that a required graphics feature is supported by the active graphics device will now work correctly.This fixes Record example plots with device requested in
figures
field instead ofragg::agg_png()
#2299. Note here is a list of graphics features whichgrDevices::dev.capabilities()
affirms support forgrDevices::png(type = "cairo")
in R 4.3 that is not affirmed in the latest version ofragg::agg_png()
because it doesn't support that feature yet: