Add functions useful for showing progress bar in R packages purrr and furrr, using package progressr.
Works well in jupyter/jupyterlab where handlers(global = TRUE) in progressr gives error, and .progress=TRUE in purrr cannot remove previous bar.
# install.packages(c('purrr', 'furrr', 'progressr'))
# mamba install r-purrr r-furrr r-progressr
source('progressively.R')
plan(multicore, workers = availableCores()%/%2)
fvmap(1:200, ~Sys.sleep(.x/100))
# |============================================ | 126/200 - base purrr and furrr function (abbreved):
map,map2,imapandpmapfmap,fmap2,fimapandfpmap
- prefix with "v": add progress bar
vmap,vmap2,vimapandvpmapfvmap,fvmap2,fvimapandfvpmap
- suffix with "s": simplified result (actually same as "_vec" suffix in purrr)
maps,map2s,imapsandpmapsfmaps,fmap2s,fimapsandfpmaps
- prefix with "v" and suffix with "s":
vmaps,vmap2s,vimapsandvpmapsfvmaps,fvmap2s,fvimapsandfvpmaps
- default handler registered for progressr is
handlers(myhandler_txtprogressbar(style = 4L, file = "", intrusiveness = 1, clear = T)), whose parameters can be changed.- style 4 is a new added one that shows the exact iteration times instead of percent.
- parameter
rpin "fv" series: since updating progress bar has performance loss especially when length of.xis large, setrpto a higher value allows only updating with a 1/rp possibility.- e.g.
future_map(1:100000, ~Sys.sleep(0.001))with 10 cores could spend 10s, but withfvmapit spends several minutes. However, settingrp=100, i.e.fvmap(1:100000, ~Sys.sleep(0.001), rp=100), only spend 14s, with (almost accurate) progress bar. - (similar to parameter
intrusivenessin progressr, but faster.)
- e.g.
- change the
chunk_sizeto 1 if the length of input list is less than 256 in furrr functions, which is beneficial for very varying sizes of input list.