rms (version 5.1-3.1)

setPb: Progress Bar for Simulations


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.


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



maximum number of iterations


type of simulation. Used for the progress bar title if tcltk is being used.


used to customize the bar label if present, overriding type


set to FALSE to override, acting as though the tcltk package were not installed


set to TRUE to not write to the console even if tcltk is unavailable and showprogressbar is not FALSE or "none"


print a message for every every iterations


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

See Also

tkProgressBar, setTkProgressBar


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
# For functions that do simulations to use the console instead of pop-up
# Even with tcltk is installed
pb <- setPb(1000, label='Random Sampling')
# }