purrr_bar {simaerep} | R Documentation |
Execute a purrr or furrr function with a progress bar.
Description
Internal utility function.
Usage
purrr_bar(
...,
.purrr,
.f,
.f_args = list(),
.purrr_args = list(),
.steps,
.slow = FALSE,
.progress = TRUE
)
Arguments
... |
iterable arguments passed to .purrr |
.purrr |
purrr or furrr function |
.f |
function to be executed over iterables |
.f_args |
list of arguments passed to .f, Default: list() |
.purrr_args |
list of arguments passed to .purrr, Default: list() |
.steps |
integer number of iterations |
.slow |
logical slows down execution, Default: FALSE |
.progress |
logical, show progress bar, Default: TRUE |
Details
Call still needs to be wrapped in with_progress
or with_progress_cnd()
Value
result of function passed to .f
Examples
# purrr::map
progressr::with_progress(
purrr_bar(rep(0.25, 5), .purrr = purrr::map, .f = Sys.sleep, .steps = 5)
)
# purrr::walk
progressr::with_progress(
purrr_bar(rep(0.25, 5), .purrr = purrr::walk,.f = Sys.sleep, .steps = 5)
)
# progress bar off
progressr::with_progress(
purrr_bar(
rep(0.25, 5), .purrr = purrr::walk,.f = Sys.sleep, .steps = 5, .progress = FALSE
)
)
# purrr::map2
progressr::with_progress(
purrr_bar(
rep(1, 5), rep(2, 5),
.purrr = purrr::map2,
.f = `+`,
.steps = 5,
.slow = TRUE
)
)
# purrr::pmap
progressr::with_progress(
purrr_bar(
list(rep(1, 5), rep(2, 5)),
.purrr = purrr::pmap,
.f = `+`,
.steps = 5,
.slow = TRUE
)
)
# define function within purr_bar() call
progressr::with_progress(
purrr_bar(
list(rep(1, 5), rep(2, 5)),
.purrr = purrr::pmap,
.f = function(x, y) {
paste0(x, y)
},
.steps = 5,
.slow = TRUE
)
)
# with mutate
progressr::with_progress(
tibble::tibble(x = rep(0.25, 5)) %>%
dplyr::mutate(x = purrr_bar(x, .purrr = purrr::map, .f = Sys.sleep, .steps = 5))
)
[Package simaerep version 0.5.0 Index]