debug_httr_get: debugging the httr::GET function

debug_httr_getR Documentation

debugging the httr::GET function

Description

By temporarily setting a trace on httr::GET the debug_httr_get function is able to retrieve the url that is used as input and the resulting response object. This is especially useful when debugging a high-level function that somewhere in a subfunction makes one of more calls to httr::GET.

Usage

debug_httr_get(fn, ret = "finalurl")

Arguments

fn

An expression that calls (indirectly) the httr::GET function

ret

A character string or a numeric vector indicating the information that should be returned from the call(s) to httr::GET. Default: finalurl. See details section.

Value

List or character value with the requested information. See Details section

Details

The function works by temporarily setting a trace on the httr::GET function. The result is a list with the requested information for each call to httr::GET that is caused by the expression in fn. If there is only one call to httr::GET the list has length 1 and will be unpacked. The possible values for fn and the returned information:

none or 'finalurl':

the full url for which the httr::GET request is done

'inputurl':

the url structure that was the input for httr::GET request

'resp':

the resulting httr::GET response object

'json':

the formatted json representation of the content of the response object

'fjson':

the content of the response object after applying jsonlite::fromJSON

'org_result':

the original results of the expression (as if no tracing had been used)

a numeric vector:

a portion of the response object according to the vector used in purrr::pluck to extract from the response object

Examples

## Not run: 
x=debug_httr_get(  rtweet::get_trends("23424977")              )
print(x)
debug_httr_get(  rtweet::get_trends("23424977"), ret=c(9,2)  )
print(x)
x=debug_httr_get(  rtweet::get_trends("23424977"), ret='resp'  )
str(x)

## End(Not run)

HanOostdijk/HOQCutil documentation built on July 28, 2023, 5:56 p.m.