-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Description
I use future_walk to make multiple plots in parallel. Something like that:
pic_fun <- function(x) {
p <- progressor(along = x)
opts <- furrr_options(globals = c("roi_sf", "all_dates", "FILE_DB", "FLD_RESULTS"),
packages = c("DBI", "magrittr", "dplyr", "ggplot2", "sf"),
seed = NULL)
future_walk(.x = x, .options = opts, .f = ~{
...
plt <- ggplot() +
geom_sf(data = new_sf, aes(fill = SAVI / 10000, col = SAVI / 10000), size = 0.3)
...
pic_file <- file.path(FLD_RESULTS, "savi_plots_by_date", paste0(format(current_date, "%Y%m%d"), ".jpeg"))
ggsave(filename = pic_file, plot = plt, device = "jpeg", dpi = 300, units = "cm", width = 16.26*2, height = 9.14*2, quality = 95)
p()
})
}
with_progress({
plan("multisession", workers = future::availableCores() - 2)
pic_fun(x = 1:length(all_dates))
plan("sequential")
})
When i run the script I get multiple warnings:
MultisessionFuture (NULL) added, removed, or modified devices. A future expression must close any opened devices and must not close devices it did not open. Details: 1 devices differ: index=2, before=‘NA’, after=‘’
As I understand the error raises because ggsave() opens a device and it do not have time to close up before being called by a parallel process. Manual closing while (dev.cur() > 1) dev.off() does not help.
What is a proper way to save the plot in parallel without raising a warnings?
Metadata
Metadata
Assignees
Labels
No labels