From 6caf8b8e320c25d7f4bc37d406ae749a6af201e9 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 19 Jun 2025 00:45:00 -0400 Subject: [PATCH] Use local to avoid function attachment --- R/plot.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/plot.R b/R/plot.R index 2c655f72c6..9749859c6f 100644 --- a/R/plot.R +++ b/R/plot.R @@ -281,5 +281,8 @@ S7::method(convert, list(from = class_ggplot, to = S7::class_list)) <- S7::props(from) } -S7::method(as.list, class_ggplot) <- function(x, ...) convert(x, S7::class_list) -rm(`as.list`) +# S7 currently attaches the S3 method to the calling environment which gives `ggplot2:::as.list` +# Wrap in `local()` to provide a temp environment which throws away the attachment +local({ + S7::method(as.list, class_ggplot) <- function(x, ...) convert(x, S7::class_list) +})