MyNixOS website logo
Description

'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) <doi:10.1093/jamia/ocv153>.

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!

Metadata

Version

0.1.0

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows