'openFDA' API

The 'openFDA' API facilitates access to Federal Drug Agency (FDA) data on drugs, devices, foodstuffs, tobacco, and more with 'httr2'. This package makes the API easily accessible, returning objects which the user can convert to JSON data and parse. Kass-Hout TA, Xu Z, Mohebbi M et al. (2016) .


openFDA

CRANstatus R-CMD-check check-no-suggests Codecov testcoverage

openFDA makes querying the openFDA API from R a breeze. The API itself serves publicly available data from the FDA about foods, drugs, devices, and more. This data includes data such as recall enforcement reports, adverse events, manufacturer details, and - again - even more! Note that the data on openFDA has not been validated for clinical or production use.

Installation

The easiest way to install openFDA is to get it from CRAN:

install.packages("openFDA")

Development version

# install.packages("pak")
pak::pkg_install("simpar1471/openFDA")

Using openFDA

library(openFDA)

The full documentation for the API is online, so look at the openFDA website to get a full feel for the API itself.

The R package lets you query the API directly from R, using httr2.

search <- openFDA(
  search = "openfda.generic_name:furosemide",
  limit = 5
)

search
#> <httr2_response>
#> GET
#> https://api.fda.gov/drug/drugsfda.json?api_key=[API_KEY]&search=openfda.generic_name:furosemide&limit=5
#> Status: 200 OK
#> Content-Type: application/json
#> Body: In memory (26060 bytes)

The underlying response is JSON data - you can use httr2::resp_body_json() to get the JSON data as a nested list, then extract the fields you want.

json <- httr2::resp_body_json(search)

json$results[[1]]$openfda$brand_name
#> [[1]]
#> [1] "FUROSCIX"
json$results[[1]]$openfda$pharm_class_epc
#> [[1]]
#> [1] "Loop Diuretic [EPC]"

I’ve found purrr to be very useful for parsing this data quickly.

purrr::map_chr(
  .x = json$results, 
  .f = \(result) purrr::pluck(result, "openfda", "manufacturer_name", 1)
)
#> [1] "scPharmaceuticals Inc."                 
#> [2] "Graviti Pharmaceuticals Private Limited"
#> [3] "Hikma Pharmaceuticals USA Inc."         
#> [4] "Civica, Inc."                           
#> [5] "Eugia US LLC"

Other R packages for openFDA

The openfda package from rOpenHealth also wraps the openFDA API from R, and is available on GitHub. It’s got a pretty neat structure whereby you build up a query using individual functions for each parameter - though it’s my personal preference to keep these as parameters to a single function. It also makes results available in data frames, which is nice, but I think working with the response object and parsing the underlying JSON yourself permits more powerful interactions with the API.

There is also FDAopenR, which I couldn’t quite wrap my head around. The package appears to be in working order, though!

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("openFDA")

0.1.0 by Simon Parker, 2 years ago


https://github.com/simpar1471/openFDA, https://simpar1471.github.io/openFDA/


Report a bug at https://github.com/simpar1471/openFDA/issues


Browse source code at https://github.com/cran/openFDA


Authors: Simon Parker [aut, cre, cph]


Documentation:   PDF Manual  


GPL (>= 3) license


Imports cli, httr2, checkmate, purrr, rlang, vctrs

Suggests knitr, rmarkdown, testthat, stringr


See at CRAN