Skip to content

Commit 3055749

Browse files
committed
code review
1 parent 85818b1 commit 3055749

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

R/ggplotly.R

+9-8
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,13 @@ gg2list <- function(p, width = NULL, height = NULL,
419419
suppressMessages(dplyr::left_join(x, y))
420420
}, data, nestedKeys, layers)
421421

422-
# return all the objects in this environmet
423-
mget(ls(environment()), inherits = FALSE)
422+
structure(
423+
list(
424+
data = data, layout = layout, plot = plot,
425+
env = environment()
426+
),
427+
class = "ggplot_built"
428+
)
424429
}
425430

426431
# Allow thematic to add new defaults to the plot object based on it's theme
@@ -432,12 +437,8 @@ gg2list <- function(p, width = NULL, height = NULL,
432437
}
433438

434439
# ggplotly_build() returns list of objects...make them known to gg2list() env
435-
436-
env <- environment()
437-
for (var in names(built)) {
438-
assign(var, built[[var]], envir = env)
439-
}
440-
440+
attach(built$env, name = "ggplot_build_env")
441+
on.exit(detach(name = "ggplot_build_env", character.only = TRUE), add = TRUE)
441442

442443

443444
# initiate plotly.js layout with some plot-wide theming stuff

0 commit comments

Comments
 (0)