Title: | Provides Progress Bars in 'knitr' |
---|---|
Description: | 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. |
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) |
Maintainer: | Robert M Flight <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.1 |
Built: | 2024-11-20 04:50:29 UTC |
Source: | https://github.com/rmflight/knitrprogressbar |
Provides functionality to decide how the progress should be written, if at all.
make_kpb_output_decisions()
make_kpb_output_decisions()
This function makes decisions about how the progress bar should be displayed based on whether:
The code is being run in an interactive session or not
The code is part of a knitr
evaluation using knit()
or rmarkdown::render()
Options set by the user. These options include:
kpb.suppress_noninteractive: a logical value. Whether to suppress output when being run non-interactively.
kpb.use_logfile: logical, should a log-file be used for output?
kpb.log_file: character string defining the log-file to use. kpb.use_logfile must be TRUE
.
kpb.log_pattern: character string providing a pattern to use, will be combined with the chunk
label to create a log-file for each knitr chunk. kpb.use_logfile must be TRUE
.
Based on these, it will either return a newly opened connection, either via
stderr()
, stdout()
, or a file connection via file("logfile.log", open = "w")
.
Note that for files this will overwrite a previously existing file, and the contents
will be lost.
a write-able connection or NULL
## Not run: # suppress output when not interactive options(kpb.suppress_noninteractive = TRUE) # use a log-file, will default to kpb_output.txt options(kpb.use_logfile = TRUE) # use a specific log-file options(kpb.use_logfile = TRUE) options(kpb.log_file = "progress.txt") # use a log-file based on chunk names options(kpb.use_logfile = TRUE) options(kpb.log_pattern = "pb_out_") # for a document with a chunk labeled: "longcalc", this will generate "pb_out_longcalc.log" ## End(Not run)
## Not run: # suppress output when not interactive options(kpb.suppress_noninteractive = TRUE) # use a log-file, will default to kpb_output.txt options(kpb.use_logfile = TRUE) # use a specific log-file options(kpb.use_logfile = TRUE) options(kpb.log_file = "progress.txt") # use a log-file based on chunk names options(kpb.use_logfile = TRUE) options(kpb.log_pattern = "pb_out_") # for a document with a chunk labeled: "longcalc", this will generate "pb_out_longcalc.log" ## End(Not run)
This provides a reference class representing a text progress bar that displays the
estimated time remaining. When finished, it displays the total duration. The
automatic progress bar can be disabled by setting progress_location = NULL
.
progress_estimated( n, min_time = 0, progress_location = make_kpb_output_decisions() )
progress_estimated( n, min_time = 0, progress_location = make_kpb_output_decisions() )
n |
Total number of items |
min_time |
Progress bar will wait until at least |
progress_location |
where to write the progress to. Default is to make
decisions based on location type using |
A ref class with methods tick()
, print()
,
pause()
, and stop()
.
p <- progress_estimated(3) p$tick() p$tick() p$tick() p <- progress_estimated(3) for (i in 1:3) p$pause(0.1)$tick()$print() p <- progress_estimated(3) p$tick()$print()$ pause(1)$stop() # If min_time is set, progress bar not shown until that many # seconds have elapsed p <- progress_estimated(3, min_time = 3) for (i in 1:3) p$pause(0.1)$tick()$print() ## Not run: p <- progress_estimated(10, min_time = 3) for (i in 1:10) p$pause(0.5)$tick()$print() # output to stderr p <- progress_estimated(10, progress_location = stderr()) # output to a file p <- progress_estimated(10, progress_location = tempfile(fileext = ".log")) ## End(Not run)
p <- progress_estimated(3) p$tick() p$tick() p$tick() p <- progress_estimated(3) for (i in 1:3) p$pause(0.1)$tick()$print() p <- progress_estimated(3) p$tick()$print()$ pause(1)$stop() # If min_time is set, progress bar not shown until that many # seconds have elapsed p <- progress_estimated(3, min_time = 3) for (i in 1:3) p$pause(0.1)$tick()$print() ## Not run: p <- progress_estimated(10, min_time = 3) for (i in 1:10) p$pause(0.5)$tick()$print() # output to stderr p <- progress_estimated(10, progress_location = stderr()) # output to a file p <- progress_estimated(10, progress_location = tempfile(fileext = ".log")) ## End(Not run)
Sets up a progress object that writes to a shared file to indicate the total
progress. Progress can be monitored by watch_progress_mp
.
set_progress_mp(write_location = NULL)
set_progress_mp(write_location = NULL)
write_location |
where to save progress to |
ProgressMP
watch_progress_mp
Takes care of updating a progress bar and stopping when appropriate
update_progress(.pb = NULL)
update_progress(.pb = NULL)
.pb |
the progress bar object |
the progress bar
sets up a "watcher" function that will report on the progress
of a multi-process process that is being indicated by set_progress_mp
.
watch_progress_mp( n, min_time = 0, watch_location = NULL, progress_location = make_kpb_output_decisions() )
watch_progress_mp( n, min_time = 0, watch_location = NULL, progress_location = make_kpb_output_decisions() )
n |
number of times process is running |
min_time |
how long to wait |
watch_location |
where is the progress being written to |
progress_location |
where to write the progress output |
ProgressMPWatcher
set_progress_mp