Skip to content
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

purrr example in readme? #62

Closed
pgensler opened this issue Feb 17, 2018 · 8 comments
Closed

purrr example in readme? #62

pgensler opened this issue Feb 17, 2018 · 8 comments

Comments

@pgensler
Copy link

It would be really helpful to have an example like the following in the readme for purrr:

library(purrr)
library(dplyr)
# 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)
  })

Do you think this is a bit hacky code, as you are sleeping every .5 seconds?

@gaborcsardi
Copy link
Member

Do you want to submit a PR?

@cderv
Copy link

cderv commented Feb 17, 2018

This example came up in a discussion in tidyverse/purrr#149. I was thinking that everyone looking for progress bar in purrr would eventually find the issue with the example. At the time, I was also wondering if this example belonged more to dplyr or purrr, in examples for map or a vignette. Indeed, Readme is also an option
However, as there is this progress 📦 and the answer in the discussion mentionned some work on parallelism that could change the way it works. So I told myself that the example in the issue was enough for the time, and that maybe a post in community.rstudio.com to show this example would be helpful.

Do You think it should belong in the readme ?

@pgensler
Copy link
Author

@gaborcsardi I think this is a good example of how it can be used, but I just wanted to make sure it's not a hacky solution to put in a readme. @cderv the only objection I have is the Sys.sleep call, which to me, seems a bit unnecessary?

@cderv
Copy link

cderv commented Feb 18, 2018

It was just an easy and dummy example to show how it works. the pause is here to let the progress bar appears on screen with small steps. The examples in the readme are also using Sys.sleep.
We could work on another more realistic example but not sure it is necessary to show how it works. If you have an idea and want to make the PR, feel free. what do you say?

@pgensler
Copy link
Author

Yeah I have an example where I've tried to do some web scraping with purrr, which would be perfect for the progress bars. I'd be down to do a PR, and update this thread for your comments?

@cderv
Copy link

cderv commented Feb 18, 2018

A web scraping example is a great use case. I still believe that for a readme example to show how it works a very simple example is enough. A more thorough use case of application could belong to a blog post or other documentation. However, if you believe it fits, go ahead with the PR with a link to this issue. If you want my comment, i'll be happy to do so in the opened PR.

@gaborcsardi
Copy link
Member

Any example is good, it does not have to be realistic. You do the artificial example, you don't need to sum(), even just create a function that sleeps, call that in the map() and add a comment that the real computation goes there, this is just a placeholder. Thanks!

@gaborcsardi
Copy link
Member

Please reopen if you want to submit an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants