Learn R Programming

pbapply (version 1.2-0)

pboptions: Creating Progress Bar and Setting Options

Description

Creating progress bar and setting options.

Usage

pboptions(...)
startpb(min = 0, max = 1)
setpb(pb, value)
getpb(pb)
closepb(pb)
dopb()

Arguments

...
Arguments in tag = value form, or a list of tagged values. The tags must come from the parameters described below.
pb
A progress bar object created by startpb.
min, max
Finite numeric values for the extremes of the progress bar. Must have min < max.
value
New value for the progress bar.

Value

  • When parameters are set by pboptions, their former values are returned in an invisible named list. Such a list can be passed as an argument to pboptions to restore the parameter values. Tags are the following:
  • typeType of the progress bar: timer ("timer"), text ("txt"), Windows ("win"), TclTk ("tk"), or none ("none"). Default value is "timer" progress bar with estimated remaining time.
  • charThe character (or character string) to form the progress bar. Default value is "+".
  • txt.widthThe width of the text based progress bar, as a multiple of the width of char. If NA, the number of characters is that which fits into getOption("width"). Default value is 50.
  • gui.widthThe width of the GUI based progress bar in pixels: the dialogue box will be 40 pixels wider (plus frame). Default value is 300.
  • styleThe style of the bar, see txtProgressBar. Default value is 3.
  • initialInitial value for the progress bar. Default value is 0.
  • titleCharacter string giving the window title on the GUI dialogue box. Default value is "R progress bar".
  • labelCharacter string giving the window label on the GUI dialogue box. Default value is "".
  • For startpb a progress bar object.

    For getpb and setpb, a length-one numeric vector giving the previous value (invisibly for setpb). The return value is NULL if the progress bar is turned off by getOption("pbapply.pb") ("none" or NULL value).

    dopb returns a logical value if progress bar is to be shown based on the option getOption("pbapply.pb"). It is FALSE if the type of progress bar is "none" or NULL.

    For closepb closes the connection for the progress bar.

Details

pboptions is a convenient way of handling options related to progress bar.

Other functions can be used for conveniently adding progress bar to for-like loops (see Examples).

See Also

Progress bars used in the functions: #ifdef windows winProgressBar, #endif timerProgressBar, txtProgressBar, tkProgressBar

Examples

Run this code
## for loop
fun1 <- function() {
    pb <- startpb(0, 10)
    on.exit(closepb(pb))
    for (i in 1:10) {
        Sys.sleep(0.15)
        setpb(pb, i)
    }
    invisible(NULL)
}
## while loop
fun2 <- function() {
    pb <- startpb(0, 10-1)
    on.exit(closepb(pb))
    i <- 1
    while (i < 10) {
        Sys.sleep(0.15)
        setpb(pb, i)
        i <- i + 1
    }
    invisible(NULL)
}
## using original settings
fun1()
## resetting pboptions
opb <- pboptions(style=1, char=">")
## check new settings
getOption("pboptions")
## running again with new settings
fun2()
## resetting original
pboptions(opb)
## check reset
getOption("pboptions")
fun1()

Run the code above in your browser using DataLab