JBuildProgressBar: Creates a general purpose progress bar that reports remaining...

View source: R/progressbar.R

JBuildProgressBarR Documentation

Creates a general purpose progress bar that reports remaining elapsed time rather than number of items.

Description

This function attempts to guess the total elapsed time based on time so far and numItems.

Usage

JBuildProgressBar(
  progressBar = c("text", "win", "tk", "none"),
  numItems,
  title = NULL,
  showPC = FALSE
)

Arguments

progressBar

Type of progress bar.

numItems

Number of items to be processed.

title

Optional message displayed on the progress bar.

showPC

If TRUE, include percent complete in progress message.

Details

The progress bar can be displayed as a Windows popup, a TCL popup, text printed to the console, or no progress bar depending on the value of progressBar.

The function (fn) returned by this function is usually called with no arguments, once for each item to be processed. Call fn(close = TRUE) to close the progress bar without processing all items. If the number of items to be processed changes dynamically, call fn(numNumItems = x).

Value

A function which should be called for each item as it is processed.

Examples

## Not run: 
n <- 20
pb <- JBuildProgressBar("win", numItems = n, title = "Progress")
for (i in 1:n) {
  # Execute slow task
  Sys.sleep(runif(1, max = 1))
  # Update progress bar
  pb()
}

# Optionally force close in case there weren't as many items as we expected
pb(close = TRUE)
# Optionally report total elapsed time
pb(printElapsed = TRUE)

## End(Not run)


JimMcL/JUtils documentation built on Nov. 7, 2024, 11:25 a.m.