Ever wanted a progress bar output visible in a knitr document? Now you can!
packages
R
developement
Author
Robert M Flight
Published
February 19, 2018
TL;DR
If you like dplyr progress bars, and wished you could use them everywhere, including from within Rmd documents, non-interactive shells, etc, then you should check out knitrProgressBar (crangithub).
Why Yet Another Progress Bar??
I didn’t set out to create another progress bar package. But I really liked dplyrs style of progress bar, and how they worked under the hood (thanks to the examples from Bob Rudis).
As I used them, I noticed that no progress was displayed if you did rmarkdown::render() or knitr::knit(). That just didn’t seem right to me, as that means you get no progress indicator if you want to use caching facilities of knitr. So this package was born.
How??
These are pretty easy to setup and use.
library(knitrProgressBar)# borrowed from example by @hrbrmstrarduously_long_nchar <-function(input_var, .pb=NULL) {update_progress(.pb) # function from knitrProgressBarSys.sleep(0.01)nchar(input_var)}# using stdout() here so progress is part of documentpb <-progress_estimated(26, progress_location =stdout())purrr::map(letters, arduously_long_nchar, .pb = pb)
|====== | 12% ~0 s remaining
|================ | 31% ~0 s remaining
|=========================== | 50% ~0 s remaining
|===================================== | 69% ~0 s remaining
|=============================================== | 88% ~0 s remaining
Completed after 0 s
The main difference to dplyrs progress bars is that here you have the option to set where the progress gets written to, either automatically using the built-in make_kpb_output_decisions(), or directly. Also, I have provided the update_progress function to actually do the updating or finalizing properly.
There are also package specific options to control how the decisions are made.
As of V1.1.0 (should be on CRAN soon), the package also supports indicating progress on multi-processed jobs. See the included vignette for more information.
By the way, I know this method is not ideal, but I could not get the combination of later and processx to work in my case. If anyone is willing to help out, that would be great.