gracefully {wikkitidy} | R Documentation |
Gracefully request a resource from Wikipedia
Description
The main purpose of this function is to enable examples using live resources
in the documentation. Examples must not throw errors, according to CRAN
policy. If you wrap a requesting method in gracefully
, then any
errors of type httr2_http
will be caught and no error will be thrown.
Usage
gracefully(request_object, request_method)
Arguments
request_object |
A |
request_method |
The desired function for performing the request, typically one of those in get_query_results |
Value
The output of request_method
called on request_object
, if the
request was successful. Otherwise a httr2_response
object with details
of the failed request.
Examples
# This fails without throwing an error
req <- httr2::request(httr2::example_url()) |>
httr2::req_url_path("/status/404")
resp <- gracefully(req, httr2::req_perform)
print(resp)
# This request succeeds
req <- httr2::request(httr2::example_url())
resp <- gracefully(req, httr2::req_perform)
print(resp)
[Package wikkitidy version 0.1.13 Index]