openFDA

An R package for the openFDA API (https://open.fda.gov/apis)

https://github.com/simpar1471/openfda

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.7%) to scientific vocabulary

Keywords

openfda openfda-api rstats rstats-package
Last synced: 10 months ago · JSON representation

Repository

An R package for the openFDA API (https://open.fda.gov/apis)

Basic Info
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • Open Issues: 1
  • Releases: 1
Topics
openfda openfda-api rstats rstats-package
Created over 1 year ago · Last pushed 11 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Codemeta

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# openFDA


[![CRAN status](https://www.r-pkg.org/badges/version-last-release/openFDA)](https://CRAN.R-project.org/package=openFDA)
[![R-CMD-check](https://github.com/simpar1471/openFDA/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/simpar1471/openFDA/actions/workflows/R-CMD-check.yaml)
[![check-no-suggests](https://github.com/simpar1471/openFDA/actions/workflows/check-no-suggests.yaml/badge.svg)](https://github.com/simpar1471/openFDA/actions/workflows/check-no-suggests.yaml)
[![Codecov test coverage](https://codecov.io/gh/simpar1471/openFDA/graph/badge.svg?token=1Y7FL87Z21)](https://codecov.io/gh/simpar1471/openFDA)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![pkgcheck](https://github.com/simpar1471/openFDA/workflows/pkgcheck/badge.svg)](https://github.com/simpar1471/openFDA/actions?query=workflow%3Apkgcheck)
[![Status at rOpenSci Software Peer Review](https://badges.ropensci.org/714_status.svg)](https://github.com/ropensci/software-review/issues/714)


openFDA makes querying the [openFDA API](https://open.fda.gov/apis/) 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.
However, given a spate of recent improvements which are not yet on CRAN, you may have a better time using the development version.
Nonetheless, to install from CRAN:
```r
install.packages("openFDA")
```

### Development version
```r
# install.packages("pak")
pak::pkg_install("simpar1471/openFDA")
```

## Using openFDA
```{r load_openFDA}
library(openFDA)
```

The full documentation for the API is online, so look at the [openFDA 
website](https://open.fda.gov/apis/) to get a full feel for the API itself.

Before using the package, you will need to generate an API key on the [openFDA website](https://open.fda.gov/apis/authentication/).
With an API key you can make 240 requests per minute, and are limited to 120,000 requests per day (the package will handle this request rate throttling for you).
Without a key, you can only make 1000 requests a day.
For this package, if you try to run `openFDA()` without setting an API key, it will fail:

```{r store_api_key, echo = FALSE, eval = TRUE}
rlang::push_options(openFDA.paging = "never",
                    openFDA.paging_verbosity = "quiet")
encrypted_api_key <- paste0("TEaDtqdFMq9_Montij5p9IY6T57IyqkbF8IYFVOpk-",
                            "ttxotFUNdJSxgccAnkq4nQhplaf-r3deQ")
decrypted_api_key <- httr2::secret_decrypt(encrypted_api_key, "OPENFDA_KEY")
suppressWarnings(try(
  keyring::key_delete("OPENFDA_KEY", "openFDA", "openFDA"),
  silent = TRUE)
)
suppressWarnings(try(
  keyring::key_delete("OPENFDA_KEY", "openFDA"), silent = TRUE)
)
```

```{r no_api_key, error = TRUE}
search <- openFDA(
  search = "openfda.generic_name:furosemide",
  limit = 5
)
```

That's not good.
To fix this error, get an API key from the webpage linked above.
Once you have your API key, use `set_api_key()` to store your API key.
Once you run this function, **openFDA** will 'know' your API key, even for future sessions:

```{r setting_api_key_fake, echo = TRUE, eval = TRUE}
# n.b. this API key is a fake, just for demonstration
set_api_key(api_key = "iHXeqlbXtlYEwX9MYLwyCBuiZxfn98Sj3oX2FNtSx")
```

```{r setting_api_key_real, echo = FALSE, eval = TRUE, message = FALSE}
set_api_key(api_key = decrypted_api_key)
```

Let's try using `openFDA()` again, now that you have an API key:

```{r example1_query}
search <- openFDA(
  search = "openfda.generic_name:furosemide",
  limit = 5
)

search
```

The returned `httr2` response object contains JSON data from the API - you can use `httr2::resp_body_json()` to extract the JSON data as a nested list, then extract the fields you want.

```{r example2_json}
json <- httr2::resp_body_json(search)

json$results[[1]]$openfda$brand_name
json$results[[1]]$openfda$pharm_class_epc
```

I've found [purrr](https://purrr.tidyverse.org/) to be very useful for parsing this data quickly.

```{r example3_purrr}
purrr::map_chr(
  .x = json$results, 
  .f = \(result) purrr::pluck(result, "openfda", "manufacturer_name", 1)
)
```

## Other R packages for openFDA

The [openfda](https://github.com/rOpenHealth/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](https://github.com/ck2136/FDAopenR/), which is all object-oriented.
I couldn't quite wrap my head around it, but it all appears to be in working order!

Owner

  • Name: Simon Parker
  • Login: simpar1471
  • Kind: user
  • Location: London, UK
  • Company: UCL

PhD Student at the Unit for Lifelong Health and Ageing @ UCL. In my spare time I maintain packages for the analysis of child growth.

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "openFDA",
  "description": "The 'openFDA' API facilitates access to U.S. Food and Drug Administration (FDA) data on drugs, devices, foodstuffs, tobacco, and more. This package makes the API easily accessible with 'httr2', returning objects which the user can convert to JSON data and parse. The API is described in: Kass-Hout TA, Xu Z, Mohebbi M et al. (2016) <doi:10.1093/jamia/ocv153>.",
  "name": "openFDA: 'openFDA' API",
  "relatedLink": [
    "https://simpar1471.github.io/openFDA/",
    "https://CRAN.R-project.org/package=openFDA"
  ],
  "codeRepository": "https://github.com/simpar1471/openFDA",
  "issueTracker": "https://github.com/simpar1471/openFDA/issues",
  "license": "https://spdx.org/licenses/GPL-3.0",
  "version": "0.1.0.9002",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.3.3 (2024-02-29 ucrt)",
  "provider": {
    "@id": "https://cran.r-project.org",
    "@type": "Organization",
    "name": "Comprehensive R Archive Network (CRAN)",
    "url": "https://cran.r-project.org"
  },
  "author": [
    {
      "@type": "Person",
      "givenName": "Simon",
      "familyName": "Parker",
      "email": "simon.parker.24@ucl.ac.uk",
      "@id": "https://orcid.org/0009-0003-8214-4496"
    }
  ],
  "copyrightHolder": [
    {
      "@type": "Person",
      "givenName": "Simon",
      "familyName": "Parker",
      "email": "simon.parker.24@ucl.ac.uk",
      "@id": "https://orcid.org/0009-0003-8214-4496"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Simon",
      "familyName": "Parker",
      "email": "simon.parker.24@ucl.ac.uk",
      "@id": "https://orcid.org/0009-0003-8214-4496"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "stringr",
      "name": "stringr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=stringr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "version": ">= 3.0.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "vcr",
      "name": "vcr",
      "version": ">= 0.6.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=vcr"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 4.1.0"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "cli",
      "name": "cli",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=cli"
    },
    "3": {
      "@type": "SoftwareApplication",
      "identifier": "httr2",
      "name": "httr2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=httr2"
    },
    "4": {
      "@type": "SoftwareApplication",
      "identifier": "checkmate",
      "name": "checkmate",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=checkmate"
    },
    "5": {
      "@type": "SoftwareApplication",
      "identifier": "purrr",
      "name": "purrr",
      "version": ">= 0.2.3",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=purrr"
    },
    "6": {
      "@type": "SoftwareApplication",
      "identifier": "rlang",
      "name": "rlang",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rlang"
    },
    "7": {
      "@type": "SoftwareApplication",
      "identifier": "vctrs",
      "name": "vctrs",
      "version": ">= 0.4.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=vctrs"
    },
    "8": {
      "@type": "SoftwareApplication",
      "identifier": "prettyunits",
      "name": "prettyunits",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=prettyunits"
    },
    "9": {
      "@type": "SoftwareApplication",
      "identifier": "keyring",
      "name": "keyring",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=keyring"
    },
    "10": {
      "@type": "SoftwareApplication",
      "identifier": "memoise",
      "name": "memoise",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=memoise"
    },
    "11": {
      "@type": "SoftwareApplication",
      "identifier": "utils",
      "name": "utils"
    },
    "SystemRequirements": null
  },
  "fileSize": "406.978KB",
  "releaseNotes": "https://github.com/simpar1471/openFDA/blob/master/NEWS.md",
  "readme": "https://github.com/simpar1471/openFDA/blob/main/README.md",
  "contIntegration": [
    "https://github.com/simpar1471/openFDA/actions/workflows/R-CMD-check.yaml",
    "https://github.com/simpar1471/openFDA/actions/workflows/check-no-suggests.yaml",
    "https://codecov.io/gh/simpar1471/openFDA",
    "https://github.com/simpar1471/openFDA/actions?query=workflow%3Apkgcheck"
  ],
  "developmentStatus": "https://www.repostatus.org/#active",
  "review": {
    "@type": "Review",
    "url": "https://github.com/ropensci/software-review/issues/714",
    "provider": "https://ropensci.org"
  },
  "keywords": [
    "openfda",
    "openfda-api",
    "rstats",
    "rstats-package"
  ]
}

GitHub Events

Total
  • Create event: 6
  • Commit comment event: 4
  • Issues event: 3
  • Release event: 2
  • Watch event: 3
  • Delete event: 2
  • Issue comment event: 14
  • Push event: 65
  • Fork event: 1
Last Year
  • Create event: 6
  • Commit comment event: 4
  • Issues event: 3
  • Release event: 2
  • Watch event: 3
  • Delete event: 2
  • Issue comment event: 14
  • Push event: 65
  • Fork event: 1

Packages

  • Total packages: 1
  • Total downloads:
    • cran 194 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: openFDA

'openFDA' API

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 194 Last month
Rankings
Dependent packages count: 28.0%
Dependent repos count: 34.5%
Average: 49.7%
Downloads: 86.7%
Maintainers (1)
Last synced: 10 months ago