get_nih_data {repoRter.nih} | R Documentation |
get_nih_data
Description
Easily send a pre-made JSON request to NIH RePORTER Project API, retrieve and process the results
Usage
get_nih_data(
query,
max_pages = NULL,
flatten_result = FALSE,
return_meta = FALSE
)
Arguments
query |
A valid JSON request formatted for the RePORTER Project API, as returned
by the |
max_pages |
numeric(1); default: NULL; An integer specifying to only fetch (up to)
the first |
flatten_result |
(default: FALSE) If TRUE, flatten nested dataframes and collapse nested vectors to a single character column with elements delimited by a semi-colon |
return_meta |
(default: FALSE) If TRUE, will return a |
Details
A request to the RePORTER Project API requires retrieving paginated results, combining them, and often flattening the combined ragged data.frame to a familiar flat format which we can use in analyses. This method handles all of that for you.
Value
When return_meta = FALSE
: a tibble
containing your result set
(up to API max of 10,000 records); else if include_meta = TRUE
, a named list
containing the result set and the metadata from the initial API response.
If an API error occurs, this method will print an informative message and return NA
.
Examples
library(repoRter.nih)
## make the usual request
req <- make_req(criteria =
list(advanced_text_search =
list(operator = "Or",
search_field = "all",
search_text = "sarcoidosis lupus") ),
message = FALSE)
## get the data ragged
## Not run:
res <- get_nih_data(req,
max_pages = 1)
## get the data flattened
res_flattened <- get_nih_data(req,
flatten_result = TRUE,
max_pages = 1)
## End(Not run)