with_verbosity: Temporarily set verbosity for all requests

View source: R/verbosity.R

with_verbosityR Documentation

Temporarily set verbosity for all requests

Description

with_verbosity() and local_verbosity() are useful for debugging httr2 code buried deep inside another package, because they allow you to change the verbosity even when you don't have access to the request.

Both functions work by temporarily setting the httr2_verbosity option. You can also control verbosity by setting the HTTR2_VERBOSITY environment variable. This has lower precedence than the option, but can be more easily changed outside of R.

Usage

with_verbosity(code, verbosity = 1)

local_verbosity(verbosity, env = caller_env())

Arguments

code

Code to execture

verbosity

How much information to print? This is a wrapper around req_verbose() that uses an integer to control verbosity:

  • 0: no output

  • 1: show headers

  • 2: show headers and bodies

  • 3: show headers, bodies, and curl status messages.

Use with_verbosity() to control the verbosity of requests that you can't affect directly.

env

Environment to use for scoping changes.

Value

with_verbosity() returns the result of evaluating code. local_verbosity() is called for its side-effect and invisibly returns the previous value of the option.

Examples

fun <- function() {
  request("https://httr2.r-lib.org") |> req_perform()
}
with_verbosity(fun())

fun <- function() {
  local_verbosity(2)
  # someotherpackage::fun()
}

r-lib/httr2 documentation built on Feb. 18, 2025, 8:45 p.m.