Last active
May 6, 2020 18:31
-
-
Save DavisVaughan/2a6316cdef7e5cebdba100db5e0fa92c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(future) | |
library(progressr) | |
library(furrr) | |
# 2 cores | |
plan(multisession, workers = 2L) | |
x <- 1:20 | |
random_sleep <- function() { | |
Sys.sleep(sample(1:3, size = 1L)) | |
} | |
with_progress({ | |
# Create a progressor | |
p <- progressor(along = x) | |
future_map(x, ~{ | |
# Sleep for a random amount of time | |
random_sleep() | |
# Tick the progress bar | |
p() | |
}) | |
}) | |
# shut down the workers | |
plan(sequential) |
Woops! Thanks - updated
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minor: To shut down workers, you need to switch to another plan -
plan(sequential)
is a good choice. Usingplan()
will only display the currently set future plan.