r-lib / httr2

Make HTTP requests and process their responses. A modern reimagining of httr.
https://httr2.r-lib.org
Other
238 stars 59 forks source link

Issue in progress (documentation) #557

Open JBGruber opened 3 weeks ago

JBGruber commented 3 weeks ago

I looks like the documentation of ?httr2::progress_bars is wrong:

https://github.com/r-lib/httr2/blob/5380f2107ea5a8e47def600e28009b5be1b8928a/R/progress-bars.R#L33-L35

Here is a reproducible example:

library(httr2)
req <- request(example_url()) |> 
  req_url_path("/delay/0.5")

reqs <- rep(list(req), 15)

pb_config <- list(
  show_after = 0
)

resps <- httr2::req_perform_parallel(
  reqs = reqs,
  on_error = "continue",
  progress = pb_config
)

It fails with:

Error in (function (name = NULL, status = NULL, type = c("iterator", "tasks",  : 
  unused argument (show_after = 0)

I tried to track down where the progress is handed to cli and I think that's here for the case of a named list:

https://github.com/r-lib/httr2/blob/5380f2107ea5a8e47def600e28009b5be1b8928a/R/utils.R#L278

However, cli::cli_progress_bar lost the show_after parameter a while ago.

A workaround would be to set cli.progress_show_after temporarily:

req_perform_parallel2 <- function(..., progress) {
  show_after <- progress$show_after
  progress$show_after <- NULL
  resps <- withr::with_options(
    list(cli.progress_show_after = show_after), 
    httr2::req_perform_parallel(..., progress = progress)
  )
}

resps <- req_perform_parallel2(
  reqs = reqs,
  on_error = "continue",
  progress = pb_config
)

Happy to make a PR either fixing the documentation or the function with the workaround.