make_req {repoRter.nih}R Documentation

make_req

Description

Easily generate a json request with correct schema to be passed to NIH RePORTER Project API

Usage

make_req(
  criteria = list(fiscal_years = lubridate::year(Sys.Date())),
  include_fields = NULL,
  exclude_fields = NULL,
  offset = 0,
  limit = 500,
  sort_field = NULL,
  sort_order = NULL,
  message = TRUE
)

Arguments

criteria

list(); the RePORTER Project API query criteria used to filter results (projects). See Details for schema and other spec rules.

include_fields

character(); optional; use to return only the specified fields from the result. See Details for valid return field names

exclude_fields

character(); optional; use to exclude specified fields from the result.

offset

integer(1); optional; default: 0; usually not explicitly passed by user. Used to set the start index of the results to be retrieved (indexed from 0). See Details.

limit

integer(1); optional; default: 500; restrict the number of project records returned per page/request inside the calling function. Defaulted to the maximum allowed value of 500. Reducing this may help with bandwidth/timeout issues.

sort_field

character(1); optional; use to sort the result by the specified field. May be useful in retrieving complete result sets above the API maximum of 10K (but below 2x the max = 20K)

sort_order

character(1): optional; one of "asc" or "desc"; sort_field must be specified.

message

logical(1); default: TRUE; print a message with the JSON to console/stdout. You may want to suppress this at times.

Details

The maximum number of records that can be returned from any result set is 10,000. Also, the maximum record index in the result set that can be returned is 9,999 - corresponding to the 10,000'th record in the set. These constraints from the NIH API defy any intuition that the offset argument would be useful to return records beyond this 10K limit. If you need to do this, you have two options:

criteria must be specified as a list and may include any of the following (all optional) top level elements:

Field Names

Full listing of available field names which can be specified in include_fields, exclude_fields, and sort_field is located here

Value

A standard json (jsonlite flavor) object containing the valid JSON request string which can be passed to get_nih_data or elsewhere

Examples

library(repoRter.nih)

## all projects funded in the current (fiscal) year
req <- make_req() 

## projects funded in 2019 through 2021
req <- make_req(criteria = list(fiscal_years = 2019:2021))

## projects funded in 2021 where the principal investigator first name is
## "Michael" or begins with "Jo" 
req <- make_req(criteria = 
                    list(fiscal_years = 2021,
                         pi_names = 
                             list(first_name = c("Michael", "Jo*"),
                                  last_name = c(""), # must specify
                                  any_name = character(1) # same here
                                  )
                         )
                )

## all covid-related projects except those funded by American Rescue Plan
## and specify the fields to return, sorting ascending on ApplId column
req <- make_req(criteria = 
                    list(covid_response = c("Reg-CV", "CV", "C3", "C4", "C5")
                    ),
                include_fields = 
                    c("ApplId", "SubprojectId", "FiscalYear", "Organization",
                      "AwardAmount", "CongDist", "CovidResponse",
                      "ProjectDetailUrl"),
                sort_field = "ApplId",
                sort_order = "asc")
                
## using advanced_text_search with boolean search string

string <- "(head AND trauma) OR \"brain damage\" AND NOT \"psychological\""
req <- make_req(criteria = 
                    list(advanced_text_search =
                         list(operator = "advanced",
                              search_field = c("terms", "abstract"),
                              search_text = string
                              )
                         )
                )


[Package repoRter.nih version 0.1.4 Index]