with_progress_cnd {simaerep} | R Documentation |
Conditional with_progress
.
Description
Internal function. Use instead of
with_progress
within custom functions with progress
bars.
Usage
with_progress_cnd(ex, progress = TRUE)
Arguments
ex |
expression |
progress |
logical, Default: TRUE |
Details
This wrapper adds a progress parameter to with_progress
so that we can control the progress bar in the user facing functions. The progressbar
only shows in interactive mode.
Value
No return value, called for side effects
See Also
Examples
if (interactive()) {
with_progress_cnd(
purrr_bar(rep(0.25, 5), .purrr = purrr::map, .f = Sys.sleep, .steps = 5),
progress = TRUE
)
with_progress_cnd(
purrr_bar(rep(0.25, 5), .purrr = purrr::map, .f = Sys.sleep, .steps = 5),
progress = FALSE
)
# wrap a function with progress bar with another call with progress bar
f1 <- function(x, progress = TRUE) {
with_progress_cnd(
purrr_bar(x, .purrr = purrr::walk, .f = Sys.sleep, .steps = length(x), .progress = progress),
progress = progress
)
}
# inner progress bar blocks outer progress bar
progressr::with_progress(
purrr_bar(
rep(rep(1, 3),3), .purrr = purrr::walk, .f = f1, .steps = 3,
.f_args = list(progress = TRUE)
)
)
# inner progress bar turned off
progressr::with_progress(
purrr_bar(
rep(list(rep(0.25, 3)), 5), .purrr = purrr::walk, .f = f1, .steps = 5,
.f_args = list(progress = FALSE)
)
)
}
[Package simaerep version 0.5.0 Index]