2

I am wondering how to convert this example code to purrr style by using the walk() function instead?

library(cli)

n <- 10
cli_alert_info("About to start downloads of {n} file{?s}")

i <- 0
cli_progress_step("Got {i}/{n} {qty(i)}file{?s}.")

for (i in seq_len(n)) {
  Sys.sleep(0.5)
  cli_progress_update()
}

Any comments and suggestions are greatly appreciated.

1 Answer 1

4

You could use the .progress argument. See Progress bars in purrr for more details.

library(cli)

n <- 10
cli_alert_info("About to start downloads of {n} file{?s}")

purrr::walk(seq_len(n), ~ {
  Sys.sleep(0.5)
}, .progress = list(type = "iterator",
                    format = "Got {pb_current}/{pb_total} {qty(pb_current)}file{?s}.",
                    clear = FALSE))

# ℹ About to start downloads of 10 files
# Got 10/10 files.
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Darren. I am just wondering where are pb_current and pb_total defined? (I tried with other values but they didn't work) , or they are terms reserved for this specific usage?
@Grasshopper_NZ They are defined in progress bar variables from {cli} package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.