setPb {rms} | R Documentation

## Progress Bar for Simulations

### Description

Depending on prevailing `options(showprogress=)` and availability of the `tcltk` package, sets up a progress bar and creates a function for simple updating of the bar as iterations progress. Setting `options(showprogressbar=FALSE)` or `options(showprogressbar='none')` results in no progress being shown. Setting the option to something other than `"tk"` or `"none"` results in the console being used to show the current iteration number and intended number of iterations, the same as if `tcltk` is not installed. It is not recommended that the `"tk"` be used for simulations requiring fewer than 10 seconds for more than 100 iterations, as the time required to update the pop-up window will be more than the time required to do the simulations. This problem can be solved by specifying, for example, `every=10` to `setPb` or to the function created by `setPb`, or by using `options(showevery=10)` before `setPb` is called. If `options(showprogress=)` is not specified, progress is shown in the console with an iteration counter.

### Usage

    setPb(n, type = c("Monte Carlo Simulation", "Bootstrap",
                      "Cross-Validation"),
             label, usetk = TRUE, onlytk=FALSE, every=1)

### Arguments

`n` | maximum number of iterations
`type` | type of simulation. Used for the progress bar title if `tcltk` is being used.
`label` | used to customize the bar label if present, overriding `type`
`usetk` | set to `FALSE` to override, acting as though the `tcltk` package were not installed
`onlytk` | set to `TRUE` to not write to the console even if `tcltk` is unavailable and `showprogressbar` is not `FALSE` or `"none"`
`every` | print a message for every `every` iterations

### Value

a function that should be called by the user once per iteration, specifying the iteration number as the sole argument

### Author(s)

Frank Harrell

### See Also

`tkProgressBar`, `setTkProgressBar`

### Examples

    ## Not run:
    options(showprogress=TRUE)   # same as ='tk'
    pb <- setPb(1000)
    for(i in 1:1000) {
       pb(i)   # pb(i, every=10) to only show for multiples of 10
       # your calculations
      }
    # Force rms functions to do simulations to not report progress
    options(showprogress='none')
    # For functions that do simulations to use the console instead of pop-up
    # Even with tcltk is installed
    options(showprogress='console')
    pb <- setPb(1000, label='Random Sampling')

    ## End(Not run)

[Package rms version 5.1-2 Index]