Skip to content

Support saving objects from grDevices::recordPlot() #6494

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

Closed
wants to merge 1 commit into from

Conversation

ppoyk
Copy link

@ppoyk ppoyk commented Jun 5, 2025

Add support for saving plot objects created by the recordPlot function from the base-R-bundled grDevices package. The dedicated function replayPlot is used in a new grid.draw method to display a recordedplot in a device.

This enables ggsave to be used more flexibly with base R code.

Add support for saving plot objects created by the `recordPlot` function from the bundled `grDevices` package. The dedicated function `replayPlot` is used in a new `grid.draw` method to display a `recordedplot` in a device.

 This enables `ggsave` to be used more flexibly with base R code.
@teunbrand
Copy link
Collaborator

Hi there, thanks for the PR!
Just for clarification because there is no associated issue: what is the problem that this PR aims to solve?
From your description it seems you want ggsave() to work with base R plots, is that correct?
Can you give an example how this would be used?

@thomasp85
Copy link
Member

Thanks for this contribution. However, it is not the objective of ggsave() to be used for anything other than saving ggplots and as such we are not going to merge it

@thomasp85 thomasp85 closed this Jun 5, 2025
@ppoyk
Copy link
Author

ppoyk commented Jun 6, 2025

That's unfortunate.

As ggsave is very user-friendly and intuitive function to use, it is ubiquitous for saving plots.
It would be handy to be able to save all major plot types (grid|base R) with just one function.

For posterity:
You can add the capability for ggsave() to save plot objects from recordPlot(). Globally define a new S3 method for grid.draw(), which is used internally by ggsave().

grid.draw.recordedplot <- function(x) { replayPlot(x) }

The class produced by recordPlot() is "recordedplot".

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

Successfully merging this pull request may close these issues.

3 participants