futureverse / futureverse/future.apply
Include simple .progress switch in future_lapply
- Dominant language
- R
- Stars
- 218
- Forks
- 20
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 1
Description
Both purrr and furrr's `map*` functions have a `.progress` switch to enable a progress bar. It would be very convenient to also have it available, e.g. in future_lapply.
Here is a quick implementation of a `.progress` switch which uses a CLI-based progress bar, that is also in use in purrr and that [also seems to be favoured](https://github.com/DavisVaughan/furrr/issues/138#issuecomment-1477777131) by furrr:
```r
library("future")
library("future.apply")
library("progressr")
f <- function(x){
Sys.sleep(.01)
x
}
future_lapply_progress <- function(X, FUN, ..., .progress = FALSE){
handlers("cli")
if(.progress == TRUE){
with_progress({
nX <- length(X)
p <- progressor(nX)
FUN_progress <- function(X, ...) {
res <- FUN(X, ...)
p()
res
}
future_lapply(X, FUN_progress, ...)
})
} else {
future_lapply(X, FUN, ...)
}
}
res <- future_lapply_progress(1:100, f, .progress = F)
res <- future_lapply_progress(1:100, f, .progress = T)
```
I know about futureverses "back-end/ront-end" design philisophy to separate progress signaling from displaying progress. However, if one quickly wants to parallelize some lapply-type code in RStudio, having a simple .progress switch is more convenient than having to set up the progressor, including it in the function to be parallelized, wrapping it in a `with_progress()` and remembering/researching how these three pieces fit together. Also, this implementation would possibly serve as a template to update the furrr's `.progress` implementation to using the CLI package.
Contributor guide
Assessment
This issue has not been assessed yet.