diff --git a/.claude/settings.json b/.claude/settings.json index 722e962ba..822e3a7cc 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -9,6 +9,7 @@ "Edit(R/**)", "Edit(tests/**)", "Edit(vignettes/**)", + "Edit(NEWS.md)" ], "deny": [] } diff --git a/NAMESPACE b/NAMESPACE index 7cf5bb433..6a002be56 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -148,6 +148,7 @@ export(response) export(response_json) export(resps_data) export(resps_failures) +export(resps_ok) export(resps_requests) export(resps_successes) export(secret_decrypt) diff --git a/NEWS.md b/NEWS.md index a63a849fc..3dc4da916 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # httr2 (development version) +* New `resps_ok()` returns a logical vector indicating which requests were successful (#807). * httr2 will now emit OpenTelemetry traces for all requests when tracing is enabled. Requires the `otelsdk` package (@atheriel, #729). * `req_perform_connection()` no longer errors with `no applicable method for 'close' applied to an object of class "c('httr2_failure', 'httr2_error', 'rlang_error', 'error', 'condition')` (#817). * Refactor `url_modify()` to better retain exact formatting of URL components diff --git a/R/iterate-responses.R b/R/iterate-responses.R index c6fcd6029..3a38b7904 100644 --- a/R/iterate-responses.R +++ b/R/iterate-responses.R @@ -1,16 +1,17 @@ #' Tools for working with lists of responses #' #' @description -#' These functions provide a basic toolkit for operating with lists of +#' These functions provide a basic toolkit for working with lists of #' responses and possibly errors, as returned by [req_perform_parallel()], -#' [req_perform_sequential()] and [req_perform_iterative()]. +#' [req_perform_sequential()], and [req_perform_iterative()]. #' #' * `resps_successes()` returns a list of successful responses. #' * `resps_failures()` returns a list of failed responses (i.e. errors). +#' * `resps_ok()` returns a logical vector indicating which requests were +#' successful. #' * `resps_requests()` returns the list of requests that corresponds to -#' each request. +#' each response. #' * `resps_data()` returns all the data in a single vector or data frame. -#' It requires the vctrs package to be installed. #' #' @export #' @param resps A list of responses (possibly including errors). @@ -52,6 +53,8 @@ resps_failures <- function(resps) { resps[!resps_ok(resps)] } +#' @export +#' @rdname resps_successes resps_ok <- function(resps) { vapply(resps, is_response, logical(1)) } diff --git a/man/resps_successes.Rd b/man/resps_successes.Rd index d64c44737..9f3223bb9 100644 --- a/man/resps_successes.Rd +++ b/man/resps_successes.Rd @@ -3,6 +3,7 @@ \name{resps_successes} \alias{resps_successes} \alias{resps_failures} +\alias{resps_ok} \alias{resps_requests} \alias{resps_data} \title{Tools for working with lists of responses} @@ -11,6 +12,8 @@ resps_successes(resps) resps_failures(resps) +resps_ok(resps) + resps_requests(resps) resps_data(resps, resp_data) @@ -26,16 +29,17 @@ output in \code{list()} to avoid combining all the bodies into a single raw vector, e.g. \verb{resps |> resps_data(\\(resp) list(resp_body_raw(resp)))}.} } \description{ -These functions provide a basic toolkit for operating with lists of +These functions provide a basic toolkit for working with lists of responses and possibly errors, as returned by \code{\link[=req_perform_parallel]{req_perform_parallel()}}, -\code{\link[=req_perform_sequential]{req_perform_sequential()}} and \code{\link[=req_perform_iterative]{req_perform_iterative()}}. +\code{\link[=req_perform_sequential]{req_perform_sequential()}}, and \code{\link[=req_perform_iterative]{req_perform_iterative()}}. \itemize{ \item \code{resps_successes()} returns a list of successful responses. \item \code{resps_failures()} returns a list of failed responses (i.e. errors). +\item \code{resps_ok()} returns a logical vector indicating which requests were +successful. \item \code{resps_requests()} returns the list of requests that corresponds to -each request. +each response. \item \code{resps_data()} returns all the data in a single vector or data frame. -It requires the vctrs package to be installed. } } \examples{