Provides Progress Bars in 'knitr'

Provides a progress bar similar to 'dplyr' that can write progress out to a variety of locations, including stdout(), stderr(), or from file(). Useful when using 'knitr' or 'rmarkdown', and you still want to see progress of calculations in the terminal.


CRAN_Status_Badge Build Status AppVeyor Build Status Coverage Status

knitrProgressBar

This package supplies a progress bar (shamelessly borrowed from dplyr::progress_estimated) that has options to not have output captured inside a knitr chunk.

This package is not yet on CRAN. To install this package, use devtools:

devtools::install_github("rmflight/knitrProgressBar")

Problem

You want to use knitr or rmarkdown, but you want to see the progress of a longer running calculation in the chunk. You think that you can just use dplyr::progress_estimated. But if you do, all the output from the progress bar will be suppressed (by design, actually).

Solution

This package has two functions, progress_estimated, that creates a Progress object that has a connection object associated with it, and update_progress, that properly updates the progress object. The output from the progress will be written to that connection. This connection will be either stdout (default within an R session), stderr (default from within knitr), or to a log-file.

Examples

None of these are run in this document!

Setup

library(knitrProgressBar)
 
# borrowed from example by @hrbrmstr
arduously_long_nchar <- function(input_var, .pb=NULL) {
  
  update_progress(.pb)
  
  Sys.sleep(0.5)
  
  nchar(input_var)
  
}

Let Function Decide

If you want the object to decide where to put output, do nothing. Just call the progress_estimated() function, which uses make_kpb_output_decisions():

pb <- progress_estimated(length(letters))
 
purrr::map_int(letters, arduously_long_nchar, .pb = pb)

See the help and the vignette for an explanation of how make_kpb_output_decisions() decides where to display the progress bar output.

Write to Specific Connection

If you want to write the progress out to a specific connection, just pass the connection to the progress_estimated() call:

pb <- progress_estimated(length(letters), progress_location = stdout())
 
purrr::map_int(letters, arduously_long_nchar, .pb = pb)

This includes specific files. You can then display the file, or use tailf or equivalent to watch the output of the file.

pb <- progress_estimated(length(letters), progress_location = file("progress.log", open = "w"))
 
purrr::map_int(letters, arduously_long_nchar, .pb = pb)

Connection Considerations

Each connection will display in specific situations, notably stdout() will not display to the terminal when run as part of a document being knitted.

Inspiration

This package (and the examples) was inspired by this post from Bob Rudis! Also, thanks to Hadley Wickham for the great Progress object and methods!

Website

Web accessible documentation is available here.

Bug Reports

Please submit bug reports using the GitHub issue tracker.

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

This package is licensed using an MIT license, copyright Robert M Flight.

News

knitrProgressBar 1.1.0

  • Added ability to see progress for multi-process taks. See the vignette "Progress for Multi-Processing" for more details.

knitrProgressBar 1.0.0

  • Added testing on travis-ci and appveyor.

knitrProgressBar 0.9.0

  • new function for deciding where to write the output from the progress bar, make_kpb_output_decisions(). #4. Note that this can be overridden by supplying a connection directly.

  • new function for updating the counter easily, update_progress, that provides updating and stopping the counter properly. #7

  • Added CI to the github repo. #3

  • Added testing. #5

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("knitrProgressBar")

1.1.0 by Robert M Flight, 9 months ago


https://rmflight.github.io/knitrProgressBar


Report a bug at https://github.com/rmflight/knitrProgressBar/issues


Browse source code at https://github.com/cran/knitrProgressBar


Authors: Robert M Flight [aut, cre] , Hadley Wickham [ctb] (Author of included dplyr fragments) , Romain Francois [ctb] (Author of included dplyr fragments) , Lionel Henry [ctb] (Author of included dplyr fragments) , Kirill Müller [ctb] (Author of included dplyr fragments) , RStudio [cph] (Copyright holder of included dplyr fragments)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports R6, R.oo

Suggests knitr, rmarkdown, purrr, testthat, covr, mockr, withr, parallel


See at CRAN