utils_progress | R Documentation |
Progress bars are configurable, may include percentage, elapsed time, and custom text.
progress()
: Initiate a custom progress bar of class pb_metan
.
run_progress()
: Run the progress bar and should be called within a 'for
loop' statement, a lapply()
family or purrr::map()
family of functional
programming tools.
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)
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 |
progress()
returns a list of class pb_metan
that contains the set
parameters that will called by run_progress()
.
Tiago Olivoto tiagoolivoto@gmail.com
################### 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.