progress: Display a progress bar in the console

progressR Documentation

Display a progress bar in the console

Description

A function for displaying a progress bar in the console. Useful in loops and other lengthy operations where you want some indication of progress or how long the operation will take.

Usage

progress(x, total = NULL, message = NULL)

Arguments

x

numeric. Current iteration of the progress of the operation. This would be, for example, the i in a for loop.

total

numeric. Total number of iterations until operation complete. This would be, for example, the total i in a for loop.

message

string. Optional text to add to right side of progress bar. Should not be more than a few words.

Details

Displays an updating progress bar in the console in percentage complete.

To use, place within a code block (e.g. a for loop or apply call). x should be mapped to the number of each particular iteration (e.g. the i), and total is the total expected number of iterations.

The size of the bar adjusts to the width of the R console at the time it is first run, up to a maximum total width of 80 characters (the general default R console width). It may look weird if the console width is subsequently made narrower, though the % done will remain correct.

Author(s)

Nicholas Carey - nicholascarey@gmail.com

Examples

## Not run: 
## Simple example
for(i in 1:1000) {
    Sys.sleep(0.005) # pause or it will be too quick
    progress(i, total = 1000)
    }

## Example with custom message
for(i in 1:1000) {
    Sys.sleep(0.005) # pause or it will be too quick
    progress(i, total = 1000, message = "Loop progress")
    }
    
## End(Not run)


nicholascarey/caRey documentation built on Sept. 30, 2023, 3:47 a.m.