From f9aee2d4f1fe6057514cf3873ed8100ca246e4f9 Mon Sep 17 00:00:00 2001 From: Don van den Bergh Date: Wed, 20 May 2026 23:01:08 +0200 Subject: [PATCH] avoid second call to ggplot_build --- R/plotEditing.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/plotEditing.R b/R/plotEditing.R index fce3af5e..cae26379 100644 --- a/R/plotEditing.R +++ b/R/plotEditing.R @@ -66,9 +66,12 @@ optionsDiff <- function(new, old) { #' @title Edit a plot #' @param graph a ggplot2 object #' @param newOptions an options list +#' @param ggbuild optionally a pre-computed ggplot_built object (avoids a +#' second call to \code{ggplot_build()} when the caller already built the +#' plot). #' #' @export -plotEditing <- function(graph, newOptions) { +plotEditing <- function(graph, newOptions, ggbuild = NULL) { if (!is_ggplot(graph)) stop2("graph should be a ggplot2") @@ -81,7 +84,8 @@ plotEditing <- function(graph, newOptions) { } } - ggbuild <- ggplot_build(graph) + if (is.null(ggbuild)) + ggbuild <- ggplot_build(graph) # TODO: first check if plot was previously edited, if so use those options oldOptions <- plotEditingOptions(ggbuild) validateOptions(newOptions, oldOptions)