progress | R Documentation |
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.
progress(x, total = NULL, message = NULL)
x |
numeric. Current iteration of the progress of the operation. This
would be, for example, the |
total |
numeric. Total number of iterations until operation complete. This
would be, for example, the total |
message |
string. Optional text to add to right side of progress bar. Should not be more than a few words. |
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.
Nicholas Carey - nicholascarey@gmail.com
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.