R/perform_request.R

Defines functions perform_request

#' @keywords internal
#' @noRd
perform_request <- function(req, context) {
  tryCatch(
    {
      resp <- req |>
        req_user_agent(
          "owidapi R package (https://github.com/tidy-intelligence/r-owidapi)"
        ) |>
        req_perform()
      resp
    },
    error = function(e) {
      cli::cli_abort(
        c(
          "Failed to retrieve data from Our World in Data.",
          "i" = "Error message: {conditionMessage(e)}",
          "i" = "Check your internet connection and the dataset or URL."
        ),
        call = call(context)
      )
    }
  )
}

Try the owidapi package in your browser

Any scripts or data that you put into this service are public.

owidapi documentation built on June 23, 2025, 5:08 p.m.