tidyverse / purrr

A functional programming toolkit for R
https://purrr.tidyverse.org/
Other
1.27k stars 274 forks source link

Progress bar support for `map_depth` #1058

Open dgromer opened 1 year ago

dgromer commented 1 year ago

With the current design of the map_depth function, would it be possible to also add progress bar support?

DanChaltiel commented 1 year ago

It seems that this is only a documentation issue.

map_depth(as.list(1:10), 1, ~{print(.x); Sys.sleep(1)}, .progress=T) works fine.

Sames apply for imap().

dgromer commented 1 year ago

In your example, .progress is passed to map() via .... Since you use .depth = 1, it's not distinguishable whether the progress bar is from map_depth() or from map().

If you use, for example, .depth = 2 as in map_depth(list(as.list(1:10), as.list(1:10)), 2, ~{print(.x); Sys.sleep(1)}, .progress=T) you can see that the progress bars come from map(), not from map_depth()

hadley commented 1 year ago

It's probably possible to add it, it's just quite a bit of work. And it would have to be the style of progress bar where you don't know the total number of iterations, since computing that in advance is likely to be expensive.