progressBar: Yet another progress bar

Description Usage Arguments Details Value Examples

Description

A progress bar that uses files to store progress counters with the intention that it can be used together with parallel computations.

Usage

1
2
progressBar(N, initial = 0, char = "=", width = NA, totalBar = TRUE,
  file = "", pid = FALSE)

Arguments

N

a numeric. The total number of iterations.

initial

a numeric. The initial value of the counter.

char

a character. The character used to draw the progress bar.

width

a numeric. The line width used when printing the progress bar. If NA (the default), it is getOption("width") - 10L.

totalBar

a logical. Should the progress bar be drawn for the total progress. If FALSE only the percent completion is reported.

file

a character. The file name used for printing the progress bar. The default value, "", means stdout.

pid

a logical. Should the progress for the individual processes, according to their pid, be reported (default value FALSE). Only considered if file != "". In this case, the individual progress bars are written to paste(file, "Pid", sep = "").

Details

This progress bar is based on txtProgressBar. However, instead of using a local variable associated with the progress bar object to keep track of the progress, this progress bar uses files to store the progress. The intention is that the progress bar works even when computations are carried out in parallel. It works by setting the total number N of iterations when creating the progressBar object. In each interation a counter is incremented, and the progress bar is updated with the percentage of completion as measured by the current value of the counter relative to N.

It has only been tested with mclapply from the parallel package. Option pid = TRUE only gives meaningful results in this case when mc.preschedule = TRUE for mclapply (which is the default).

With a huge number of interations and little work in each, the file IO can produce a serious overhead.

Value

An object of class progressBar containing two functions up and kill. Call up() to increment the counter and update the progress bar. Remember to call kill() after the progress bar is used to clean up.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
pb <- progressBar(100)
for(i in 1:100) {
  Sys.sleep(0.1)
  pb$up()
}
pb$kill()  ## Remember this to clean up. Removes files and directories used.
rm(pb)

## Not run: 
pb <- progressBar(100)
library(parallel)
tmp <- mclapply(1:100, function(i) {
  Sys.sleep(0.1)
  pb$up()
  }
)
pb$kill()  ## Remember this to clean up. Removes files and directories used.
rm(pb)
## End(Not run)

smde documentation built on May 2, 2019, 4:58 p.m.

Related to progressBar in smde...