get_nih_data: get_nih_data

View source: R/get_nih_data.R

get_nih_dataR 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 make_req method

max_pages

numeric(1); default: NULL; An integer specifying to only fetch (up to) the first max_pages number of pages from the result set. Useful for testing your query/obtaining schema information. Default behavior is to fetch all pages.

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 list containing your result set as well as the meta data - this includes a count of total projects matching your query and can be useful for programming.

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)


bikeactuary/repoRter.nih documentation built on Feb. 6, 2023, 8:05 p.m.