Skip to content

Commit c495e9b

Browse files
authored
Use local to avoid function attachment (#6522)
1 parent a2d0181 commit c495e9b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

R/plot.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,8 @@ S7::method(convert, list(from = class_ggplot, to = S7::class_list)) <-
281281
S7::props(from)
282282
}
283283

284-
S7::method(as.list, class_ggplot) <- function(x, ...) convert(x, S7::class_list)
285-
rm(`as.list`)
284+
# S7 currently attaches the S3 method to the calling environment which gives `ggplot2:::as.list`
285+
# Wrap in `local()` to provide a temp environment which throws away the attachment
286+
local({
287+
S7::method(as.list, class_ggplot) <- function(x, ...) convert(x, S7::class_list)
288+
})

0 commit comments

Comments
 (0)