-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress bars #149
Comments
There is a header only C++ API, isn't that good? Although I have to say that is not very well tested and have less features. https://github.com/gaborcsardi/progress#c-api |
It would also make sense to put the C++ part in another package, as it is completely independent. |
This will not work with mapping functions because we eval R functions from the C code :/ Any user interruption or R error will cause a long jump that bypasses all C++ destructors. Thus if you have any data on the heap, you'll get leaks. For example all STL containers or even a simple |
Well, there is an R API and a C++ API. It seems reasonable that you would be able to use at least one of them. :) |
+1 for this feature |
FWIW I wanted to note that I am adding some new progress bar API, which has the nice feature of having (almost) zero overhead when the progress bars are not shown (e.g. non-interactive use), in addition to ease of use. This is how it will look: progress %~~% lapply(seq, fun, ...) If progress bars are turned off, then it simply runs the I am saying this, because it would be great to use it for |
It'd probably be more purrr-like to have an adverb functional or function operator that takes mapping functionals and add progress bars to them. With a functional: # ..f must be another functional that takes a .x and a .f
# ..f must have the usual purrr signature ..f(.x, .f, ...)
with_progress <- function(..x, ..f, .f, ...) {
.f <- add_progress(.f, length(..x))
..f(..x, .f, ...)
}
mtcars %>% with_progress(map, as.character) |
A quick thought: I think it's natural to have adverb functionals when we're modifying another functional, like in the example above. But otoh it's natural to have adverb function operators when we're modifying a regular function, e.g. |
@lionel- Hmmm, maybe I misunderstand sg, but why not mtcars %>% with_progress(map)(as.character) then? Or is this what you mean in your second comment? |
yes this is what I mean. Maybe @hadley has another opinion though. |
Hmmm, actually I quite like this, no extra operator needed. Maybe I should do it with
|
mtcars %>% with_progress(vapply, sum, numeric(1))
There is some discussion about function-like looping in #168 and #135. |
I think that progress bars are so useful, there should be minimal friction to use them in purrr. That makes me think that they should be an option (like plyr), or possibly even automatically display given some conditional (e.g. loop has run for 2 seconds and has at least two more to go, like dplyr). |
How about automatically displaying them unless (a) this is not an interactive session (b) a global option is set to disable them? This is a case where it makes sense to have a global option since this is a side effect for user convenience that shouldn't have an impact on the return value. Also it'll still be possible to use Also it's still nice to have a functional to add progress bars to |
Yes, agreed about non-interactive use + global option to turn off. That's what dplyr has too. |
Will have to look if pbapply could help here. It uses global option and turned off when non-interactive. |
Also useful to display names if they're present. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@sillasgonzaga, @chris-billingham, @tiernanmartin , I am not part of the tidyverse team but I happen to know that they work on each development work by phase. There will be a As you seem to be pretty interested in progress bar, if you don't already, know that currently, even if it is not transparent in # you can also load all the tidyverse
library(dplyr)
library(purrr)
# dummy list of 10 elements with random numbers
dummy_list <- rerun(10, runif(5))
# create the progress bar with a dplyr function.
pb <- progress_estimated(length(dummy_list))
res <- dummy_list %>%
map(~{
# update the progress bar (tick()) and print progress (print())
pb$tick()$print()
Sys.sleep(0.5)
sum(.x)
}) As you see it is just two lines to add to your code. Pretty simple. It works very well with Hope it helps, and it will keep you waiting until better integration in |
I think we have 3 options to integrate progress bars functionality in
(1) is easier to code but will force the user to learn a new adverb that depends on the original function and the input (at least the input length). (2) is harder but is straightforward to the user. (3) is the most general but also the hardest to understand To solve (1), I was thinking something like this adverb using @gaborcsardi
Simple example:
The problem is that if we run this two times the progress bar is not shown, because If (1) is not enough, I think that (2) - add |
There's an fourth option as suggested by @lionel- and @hadley
That's better than (2) so it's the best approach. Would it require big changes in |
This needs to be tackled at the same time as parallelism support, which we'll start working on soon. |
@jtrecenti my vote is toward option 2, |
Can't wait! :) |
We've been using |
just wanted to chime in to say that I really dig @gaborcsardi progress package; much prefer the greater customisability over the simpler |
Reference to tidyverse/purrr#149 (comment)
I probably should have checked here first, but i have produced wrapped versions of the purrr iterators which produce progress bars using the |
call for this feature too |
Yes please!!!! |
+1 |
1 similar comment
+1 |
Hi, I just want to add that in my experience integration with |
This comment has been minimized.
This comment has been minimized.
call for this function too |
This comment has been minimized.
This comment has been minimized.
The solution providec by @cderv in #149 (comment) does not work anymore, since |
@gaborcsardi 🎉 that's fantastic! Any general pointers on whether devs should be using |
Whichever you like, but progress will not receive any new features. |
Hi,
|
A simple and natural extrapolation of @gaborcsardi 's post is the following: up <- function(x) { Sys.sleep(0.2); toupper(x) }
purrr::pmap_chr(.l = list(progress_bar=cli::cli_progress_along(letters),
to_capitalize=letters),
.f = ~up(..2)) Could have used just map2, but I just wanted to make it clear that we can keep adding as many inputs to the map statement in the list that as we need. Recommendation: add this to your code snippets! |
Would be nice to have support for progress bars in all map functions. This is a nice feature of plyr.
Could use https://github.com/gaborcsardi/progress, although we might need to ask @gaborcsardi to also provide a C API.
The text was updated successfully, but these errors were encountered: