From 107b8eb8ece67602cb96ff9f1d74f191ca1a65ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pietari=20P=C3=B6ykk=C3=B6?= <138587496+ppoyk@users.noreply.github.com> Date: Thu, 5 Jun 2025 13:25:07 +0300 Subject: [PATCH] Support saving objects from `grDevices::recordPlot()` 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. --- R/save.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/save.R b/R/save.R index 2f2faec357..6f5dd74516 100644 --- a/R/save.R +++ b/R/save.R @@ -329,6 +329,10 @@ validate_device <- function(device, filename = NULL, dpi = 300, call = caller_en grid.draw.ggplot <- function(x, recording = TRUE) { print(x) } +#' @export +grid.draw.recordedplot <- function(x) { + grDevices::replayPlot(x) +} absorb_grdevice_args <- function(f) { function(..., type, antialias) {