library(magrittr)
plan(multisession, workers = 2)
1:10 %>%
future_map(rnorm, n = 10, .options = furrr_options(seed = 123)) %>%
future_map_dbl(mean)
# If each element of the output is a data frame, use
# `future_map_dfr()` to row-bind them together:
mtcars %>%
split(.$cyl) %>%
future_map(~ lm(mpg ~ wt, data = .x)) %>%
future_map_dfr(~ as.data.frame(t(as.matrix(coef(.)))))
# You can be explicit about what gets exported to the workers.
# To see this, use multisession (not multicore as the forked workers
# still have access to this environment)
plan(multisession)
x <- 1
y <- 2
# This will fail, y is not exported (no black magic occurs)
try(future_map(1, ~y, .options = furrr_options(globals = "x")))
# y is exported
future_map(1, ~y, .options = furrr_options(globals = "y"))
# \dontshow{
# Close open connections for R CMD Check
if (!inherits(plan(), "sequential")) plan(sequential)
# }
Run the code above in your browser using DataLab