openFDA | R Documentation |
Send requests to the openFDA API
openFDA(
search = "",
sort = NULL,
count = NULL,
limit = 1000,
skip = NULL,
endpoint = "drug-drugsfda",
api_key = get_api_key(),
warn_on_http_error = TRUE
)
search |
A character vector which will be passed to
|
sort |
A single string or scalar named character vector describing how
to sort the results. The |
count |
A single string denoting a field on which to count results. If
|
limit |
A single integerish value describing the limit on the number of
records to retrieve. An error will be thrown if |
skip |
A single integer describing how many records should be skipped. If more records are skipped than are found in your search, the openFDA API will return a 404 error. |
endpoint |
A single-length character vector describing which openFDA endpoint to target.
This argument is case-sensitive. By default, the package will target the
Drugs@FDA endpoint ( |
api_key |
A single-length character vector with your openFDA API key.
By default this is the result of |
warn_on_http_error |
A scalar logical value. If |
An httr2
response object from httr2::req_perform()
. You can use
httr2::resp_body_json()
to extract JSON data from the response.
Kass-Hout TA, Xu Z, Mohebbi M, Nelsen H, Baker A, LEvine J, Johansen E, Bright RA. OpenFDA: an innovative platform providing access to a wealth of FDA's publicly available data J Am Med Inform Assoc 2016, 23(3):596-600. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/jamia/ocv153")}
format_search_term()
documents how input search
vectors are
converted to openFDA API searches.
if (httr2::secret_has_key("OPENFDA_KEY")) {
set_api_key(httr2::secret_decrypt(
"TEaDtqdFMq9_Montij5p9IY6T57IyqkbF8IYFVOpk-ttxotFUNdJSxgccAnkq4nQhplaf-r3deQ",
"OPENFDA_KEY"
))
resp <- openFDA(search = "openfda.manufacturer_name:gilead*",
limit = 2,
skip = 10)
# The function returns an `httr2` object
print(resp)
}
# Bad inputs will cause informative errors - here, a bad API key is supplied
try(
openFDA(search = "openfda.manufacturer_name:gilead*",
api_key = "BAD_API_KEY",
limit = 1)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.