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 can be installed from CRAN by:
install.packages("knitrProgressBar")
To install the development version of this package, use
remotes
:
remotes::install_github("rmflight/knitrProgressBar")
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).
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.
None of these are run in this document!
library(knitrProgressBar)
# borrowed from example by @hrbrmstr
<- function(input_var, .pb=NULL) {
arduously_long_nchar
update_progress(.pb)
Sys.sleep(0.5)
nchar(input_var)
}
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()
:
<- progress_estimated(length(letters))
pb
::map_int(letters, arduously_long_nchar, .pb = pb) purrr
See the help and the vignette for an explanation of how
make_kpb_output_decisions()
decides where to display the
progress bar output.
If you want to write the progress out to a specific connection, just
pass the connection to the progress_estimated()
call:
<- progress_estimated(length(letters), progress_location = stdout())
pb
::map_int(letters, arduously_long_nchar, .pb = pb) purrr
This includes specific files. You can then display the file, or use
tailf
or equivalent to watch the output of the file.
<- progress_estimated(length(letters), progress_location = file("progress.log", open = "w"))
pb
::map_int(letters, arduously_long_nchar, .pb = pb) purrr
Each connection will display in specific situations, notably
stdout()
will not display to the terminal when run as part
of a document being knit
ted.
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!
Web accessible documentation is available here.
Please submit bug reports using the GitHub issue tracker.
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.
This package is licensed using an MIT license, copyright Robert M Flight.