Skip to content

Instantly share code, notes, and snippets.

@jmbarbone
Created June 24, 2024 16:06
Show Gist options
  • Save jmbarbone/3fb14255eb7a26809ddedf14219768c8 to your computer and use it in GitHub Desktop.
Save jmbarbone/3fb14255eb7a26809ddedf14219768c8 to your computer and use it in GitHub Desktop.
examples of using the {progressr} package
library(progressr)
library(furrr)
handlers("void")
handlers(list(
handler_progress(
format = ":spin :current/:total (:message) [:bar] :percent in :elapsed ETA: :eta",
width = getOption("width"),
complete = "="
)
))
foo <- function(x, p = invisible) {
p <- progressor(along = x)
future_walk(
x,
function(.x, p) {
on.exit(p())
p()
message(.x)
Sys.sleep(.x)
},
p = p,
.progress = TRUE
)
}
plan(multisession, workers = 2)
with_progress(foo(runif(20)), enable = TRUE)
foo <- function(x, p = invisible) {
for (i in x) {
p()
message("i: ", i)
Sys.sleep(i)
}
invisible()
}
with_progress(enable = TRUE, {
p <- progressor(10)
foo(runif(10), p = p)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment