1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#' Use Progressr with Plyr Map-Reduce Functions
#'
#' A "progress bar" for \pkg{plyr}'s `.progress` argument.
#'
#' @param \ldots Not used.
#'
#' @return A named [base::list] that can be passed as argument `.progress`
#' to any of \pkg{plyr} function accepting that argument.
#'
#' @example incl/plyr_progress_progressr.R
#'
#' @section Limitations:
#' One can use use [doFuture::registerDoFuture()] to run \pkg{plyr} functions
#' in parallel, e.g. `plyr::l_ply(..., .parallel = TRUE)`. Unfortunately,
#' using `.parallel = TRUE` disables progress updates because, internally,
#' \pkg{plyr} forces `.progress = "none"` whenever `.parallel = TRUE`.
#' Thus, despite the \pkg{future} ecosystem and \pkg{progressr} would support
#' it, it is not possible to run \pkg{dplyr} in parallel _and_ get progress
#' updates at the same time.
#'
#' @export
progress_progressr <- function(...) {
## Progressor
p <- NULL
## List of plyr-recognized progress functions
list(
init = function(x, ...) {
p <<- progressor(x, on_exit = FALSE)
},
step = function() {
p()
},
term = function() {
p(type = "finish")
}
)
}
|