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

cli::pb_current_name #655

Closed
tvedebrink opened this issue Nov 29, 2023 · 1 comment
Closed

cli::pb_current_name #655

tvedebrink opened this issue Nov 29, 2023 · 1 comment

Comments

@tvedebrink
Copy link

Would it be possible to add an option to print the name of the current element if provided?

I have a made an example in purrr where the name is fetched from an external vector:

mtcars_cyl <- mtcars %>% split(.$cyl)

mtcars_cyl_names <- mtcars_cyl %>% names()

mtcars_cyl %>% 
  map_int(~ {
    Sys.sleep(1)
    .x %>% nrow()
  }, .progress = list(format = "{cli::pb_bar} [Cyl: {mtcars_cyl_names[{cli::pb_current}]}]", clear = FALSE)
  )
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  [Cyl: 8]
 4  6  8 
11  7 14 

Thanks for your help in advance!

@gaborcsardi
Copy link
Member

This is something that would need fixing in purrr I am afraid, because purrr knows about the vectors it is iterating over, cli does not.

But I am not even sure what the best practice is to iterate over a named vector in purrr.

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

2 participants