Thanks so much for replying Will (and thanks once again for an incredible package). Is the solution for me then, at least for the time being, just saving the .rds files in question outside of the drake_plan as the calling environment is close to empty with a clean session?
Comparisons I was doing (reprex below).
#> # A tibble: 6 x 2
#> file size
#> <fs::path> <fs::bytes>
#> 1 temp/my_ggplot.rds 285.6K
#> 2 temp/my_ggplot_drake.rds 152.9M
#> 3 temp/my_ggplotly.rds 824.7K
#> 4 temp/my_ggplotly_drake.rds 153.4M
#> 5 temp/my_plotly.rds 9.1K
#> 6 temp/my_plotly_drake.rds 153.4M
Reprex:
# Packages
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(tidyr))
suppressPackageStartupMessages(library(plotly))
suppressPackageStartupMessages(library(readr))
suppressPackageStartupMessages(library(drake))
suppressPackageStartupMessages(library(fs))
suppressPackageStartupMessages(library(here))
# Create data
my_tbl = tibble(a = rnorm(1e7, mean = 1),
b = rnorm(1e7, mean = 2))
my_summary = my_tbl %>%
summarize(across(a:b, mean)) %>%
pivot_longer(everything())
# Plot data
my_ggplot = my_summary %>%
ggplot(aes(x = name, y = value)) +
geom_col()
my_ggplotly = my_ggplot %>%
ggplotly()
my_plotly = my_summary %>%
plot_ly(x = ~name, y = ~value) %>%
add_bars()
# Create temp folder
fs::dir_create("temp")
# Saving objects outside of drake plan (to temp folder)
my_ggplot %>%
write_rds(here::here("temp", "my_ggplot.rds"))
my_ggplotly %>%
write_rds(here::here("temp", "my_ggplotly.rds"))
my_plotly %>%
write_rds(here::here("temp", "my_plotly.rds"))
###################
# drake plan starts
###################
## Same as above ##
my_drake_plan <- drake_plan(
my_tbl = tibble(a = rnorm(1e7, mean = 1),
b = rnorm(1e7, mean = 2)),
my_summary = my_tbl %>%
summarize(across(a:b, mean)) %>%
pivot_longer(everything()),
my_ggplot = my_summary %>%
ggplot(aes(x = name, y = value)) +
geom_col(),
my_ggplotly = my_ggplot %>%
ggplotly(),
my_plotly = my_summary %>%
plot_ly(x = ~name, y = ~value) %>%
add_bars(),
my_ggplot_save = my_ggplot %>%
write_rds(file_out(!!here("temp", "my_ggplot_drake.rds"))),
my_ggplotly_save = my_ggplotly %>%
write_rds(file_out(!!here("temp", "my_ggplotly_drake.rds"))),
my_plotly_save = my_plotly %>%
write_rds(file_out(!!here("temp", "my_plotly_drake.rds")))
) %>%
make()
#> ▶ target my_tbl
#> ▶ target my_summary
#> ▶ target my_ggplot
#> ▶ target my_plotly
#> ▶ target my_ggplot_save
#> ▶ target my_ggplotly
#> ▶ target my_plotly_save
#> ▶ target my_ggplotly_save
# Checking the file sizes of plots created and saved as .rds outside of drake plan
# and comparing to the same exact plots created and saved within a drake plan
tibble(file = fs::dir_ls("temp")) %>%
mutate(size = fs::file_size(file))
#> # A tibble: 6 x 2
#> file size
#> <fs::path> <fs::bytes>
#> 1 temp/my_ggplot.rds 285.6K
#> 2 temp/my_ggplot_drake.rds 152.9M
#> 3 temp/my_ggplotly.rds 824.7K
#> 4 temp/my_ggplotly_drake.rds 153.4M
#> 5 temp/my_plotly.rds 9.1K
#> 6 temp/my_plotly_drake.rds 153.4M
Created on 2020-08-13 by the reprex package (v0.3.0)