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

Issue with upcoming ggplot2 version #119

Closed
teunbrand opened this issue Mar 28, 2023 · 3 comments
Closed

Issue with upcoming ggplot2 version #119

teunbrand opened this issue Mar 28, 2023 · 3 comments

Comments

@teunbrand
Copy link
Contributor

Hi there,

While preparing for a new release of ggplot2, our reverse dependency check showed that your package's vignette has broken.
More specifically, we believe that the vignette can no longer be built due to plots being saved to disk.
We generally don't recommend saving plots to disk, partially because the saved objects may contain internal code that is version dependent.
ggplot2 tries to keep the exported functions stable, but makes no promise about internal code.
In this case, such an internal function has changed (for appealing reasons), but it invalidates plots saved to disk with previous versions of ggplot2.

In particular, we believe that the plots saved in the file below have become invalid:

inst/extdata/outputs_glmm_vignette.rda

If it is very inconvenient to circumvent saving plots to disk, please consider this issue an advance warning. The saved plots might have to be regenerated with the upcoming version of ggplot2. You can test the upcoming changes with the current release candidate, that can be installed with devtools::install_github('tidyverse/ggplot2@v3.4.2-rc').

Best wishes,
Teun

@singmann
Copy link
Owner

singmann commented Apr 4, 2023

My problem has been for a while that the plot is based on an expensive to compute model object that is also large in size. So neither saving the model nor recalculating it works while building the vignette. So far, I have saved the plot object itself, but this seems to run into problems such as this regularly.

So my question is, if there is a better way. Can I for example first transform my plot into a list using ggplot_build() and then save that resulting object? Will I be able to re-plot the returned object in the future even if ggplot2 internals change if I use print()?

@teunbrand
Copy link
Contributor Author

Yeah I can see the motivation for doing so, but it will probably keep breaking every time ggplot2 changes around some internals.
The relevant discussion on this that has happened on ggplot2's side is here: tidyverse/ggplot2#4056.

To summarise;

  • The option to save rendered plots to disk are there through ggsave().
  • Saving plot objects to disk is unsupported. It has the upside that it is easy, but the downside is that 1) it is fragile for version updates, 2) may serialise large data to disk.
  • If you must save, save the function to plot and the data separately.

For my personal two cents that may not reflect the opinion of all ggplot2 maintainers or may not conform to the stance that the package takes:
You could save the result of my_object <- ggplotGrob(my_plot) to disk. You can re-render it by using grid::grid.newpage(); grid::grid.draw(my_object). I think this is a safe-ish option if the plot needn't be edited afterwards. It adapts to window sizes as one would expect. Some extensions may define custom grobs that only work when those packages are loaded, but this should be relatively rare. The only time I personally had trouble with this strategy, was around R4.0.0 when the grid package changed their unit implementation and old plots wouldn't render anymore. Anyway, this should be less fragile than saving ggplot objects to disk directly.

@singmann
Copy link
Owner

singmann commented Apr 5, 2023

Thanks, I will try this out for all vignettes. Just need to find the time in the next days to do it for all vignettes. When done, will close this issue and update on CRAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants