utils_progress {metan} | R Documentation |
Utilities for text progress bar in the terminal
Description
Progress bars are configurable, may include percentage, elapsed time, and custom text.
-
progress()
: Initiate a custom progress bar of classpb_metan
. -
run_progress()
: Run the progress bar and should be called within a 'for loop' statement, alapply()
family orpurrr::map()
family of functional programming tools.
Usage
progress(
min = 0,
max = 100,
leftd = "|",
rightd = "|",
char = "=",
style = 2,
width = getOption("width"),
time = Sys.time()
)
run_progress(pb, actual, text = "", digits = 0, sleep = 0)
Arguments
min , max |
Numeric values for the extremes of the progress bar. Must have
|
leftd , rightd |
The left and right delimiters for the progress bar.
Defaults to |
char |
The character (or character string) to form the progress bar. |
style |
The 'style' of the progress bar. Elapsed time is counted from
calling
|
width |
The the width of the progress bar. Defaults to the number of
characters is that which fits into |
time |
The system time used to compute the elapsed time from calling
|
pb |
An object created with |
actual |
The actual value, for example, a loop variable that define the loop index value. |
text |
An optional character string to be shown at the begining of the progress bar. |
digits |
The number of significant figures in percentage value. Defaults
to |
sleep |
Suspend execution for a time interval with |
Value
progress()
returns a list of class pb_metan
that contains the set
parameters that will called by run_progress()
.
Author(s)
Tiago Olivoto tiagoolivoto@gmail.com
Examples
################### A for looping approach ################
pb <- progress()
for (i in 1:100) {
run_progress(pb, actual = i, sleep = 0.01)
}
################### An apply family approach ##############
pb <- progress(max = 10)
foo <- function(...){
run_progress(pb, ...)
rnorm(100) %>% mean()
}
(a <- sapply(1:10, FUN = foo, sleep = 0.05))
######## A purrr functional programming approach ##########
foo2 <- function(...){
run_progress(pb2, ...)
rnorm(100) %>% mean()
}
pb2 <- progress(max = 10000,
style = 4,
leftd = "",
char = ".",
rightd = "!")
b <- purrr::map_dbl(1:10000, foo2, text = "Progress bar for sampling")
hist(b)