Skip to content

zhangfeiran/progressively

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

Progressively

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.

Usage

# 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         

Functions

  • base purrr and furrr function (abbreved):
    • map, map2, imap and pmap
    • fmap, fmap2, fimap and fpmap
  • prefix with "v": add progress bar
    • vmap, vmap2, vimap and vpmap
    • fvmap, fvmap2, fvimap and fvpmap
  • suffix with "s": simplified result (actually same as "_vec" suffix in purrr)
    • maps, map2s, imaps and pmaps
    • fmaps, fmap2s, fimaps and fpmaps
  • prefix with "v" and suffix with "s":
    • vmaps, vmap2s, vimaps and vpmaps
    • fvmaps, fvmap2s, fvimaps and fvpmaps

Explanation

  • 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 rp in "fv" series: since updating progress bar has performance loss especially when length of .x is large, set rp to 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 with fvmap it spends several minutes. However, setting rp=100, i.e. fvmap(1:100000, ~Sys.sleep(0.001), rp=100), only spend 14s, with (almost accurate) progress bar.
    • (similar to parameter intrusiveness in progressr, but faster.)
  • change the chunk_size to 1 if the length of input list is less than 256 in furrr functions, which is beneficial for very varying sizes of input list.

About

Progress bar for purrr and furrr

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages