Learn R Programming

pbapply (version 1.2-1)

timerProgressBar: Timer Progress Bar

Description

Text progress bar with timer in the R console.

Usage

timerProgressBar(min = 0, max = 1, initial = 0, char = "=", width = NA, title, label, style = 1, file = "") getTimerProgressBar(pb) setTimerProgressBar(pb, value, title = NULL, label = NULL)

Arguments

min, max
(finite) numeric values for the extremes of the progress bar. Must have min < max.
initial, value
initial or new value for the progress bar. See Details for what happens with invalid values.
char
he character (or character string) to form the progress bar. If number of characters is >1, it is silently stripped to length 1.
width
the width of the progress bar, as a multiple of the width of char. If NA, the default, the number of characters is that which fits into getOption("width").
style
the style taking values between 1 and 4. 1: progress bar with elapsed and remaining time (default for this function), 2: throbber with elapsed and remaining time, 3: progress bar with remaining time printing elapsed time at the end (default for style option in pboptions), 4: throbber with remaining time printing elapsed time at the end.
file
an open connection object or "" which indicates the console.
pb
an object of class "timerProgressBar".
title, label
ignored, for compatibility with other progress bars.

Value

For timerProgressBar an object of class "timerProgressBar" inheriting from "txtProgressBar".For getTimerProgressBar and setTimerProgressBar, a length-one numeric vector giving the previous value (invisibly for setTimerProgressBar).

Details

timerProgressBar will display a progress bar on the R console (or a connection) via a text representation.

setTimerProgessBar will update the value. Missing (NA) and out-of-range values of value will be (silently) ignored. (Such values of initial cause the progress bar not to be displayed until a valid value is set.)

The progress bar should be closed when finished with: this outputs the final newline character (see closepb).

See Also

The timerProgressBar implementation follows closely the code of txtProgressBar.

Examples

Run this code
testit <- function(...)
{
    pb <- timerProgressBar(...)
    for(i in seq(0, 1, 0.05)) {
        Sys.sleep(0.2)
        setTimerProgressBar(pb, i)
    }
    Sys.sleep(0.2)
    close(pb)
}
## throbber with elapsed and remaining time
testit(style = 2)
## progress bar with remaining time
testit(width = 50, char = ".", style = 3)

Run the code above in your browser using DataLab