{"id":32199451,"url":"https://github.com/simpar1471/openfda","last_synced_at":"2025-10-22T03:16:12.649Z","repository":{"id":258288804,"uuid":"873617339","full_name":"simpar1471/openFDA","owner":"simpar1471","description":"An R package for the openFDA API (https://open.fda.gov/apis) ","archived":false,"fork":false,"pushed_at":"2025-07-22T16:31:10.000Z","size":2748,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T07:52:50.276Z","etag":null,"topics":["openfda","openfda-api","rstats","rstats-package"],"latest_commit_sha":null,"homepage":"https://simpar1471.github.io/openFDA/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simpar1471.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null}},"created_at":"2024-10-16T13:17:51.000Z","updated_at":"2025-08-01T15:53:08.000Z","dependencies_parsed_at":"2025-06-27T11:31:02.751Z","dependency_job_id":"48da9914-7e39-45a1-b88a-51b4b58ec905","html_url":"https://github.com/simpar1471/openFDA","commit_stats":null,"previous_names":["simpar1471/openfda"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/simpar1471/openFDA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpar1471%2FopenFDA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpar1471%2FopenFDA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpar1471%2FopenFDA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpar1471%2FopenFDA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simpar1471","download_url":"https://codeload.github.com/simpar1471/openFDA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpar1471%2FopenFDA/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280371890,"owners_count":26319523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openfda","openfda-api","rstats","rstats-package"],"created_at":"2025-10-22T03:16:11.308Z","updated_at":"2025-10-22T03:16:12.644Z","avatar_url":"https://github.com/simpar1471.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# openFDA\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version-last-release/openFDA)](https://CRAN.R-project.org/package=openFDA)\n[![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)\n[![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)\n[![Codecov test coverage](https://codecov.io/gh/simpar1471/openFDA/graph/badge.svg?token=1Y7FL87Z21)](https://codecov.io/gh/simpar1471/openFDA)\n[![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)\n[![pkgcheck](https://github.com/simpar1471/openFDA/workflows/pkgcheck/badge.svg)](https://github.com/simpar1471/openFDA/actions?query=workflow%3Apkgcheck)\n[![Status at rOpenSci Software Peer Review](https://badges.ropensci.org/714_status.svg)](https://github.com/ropensci/software-review/issues/714)\n\u003c!-- badges: end --\u003e\n\nopenFDA makes querying the [openFDA API](https://open.fda.gov/apis/) from R a breeze.\nThe API itself serves publicly available data from the FDA about foods, drugs, devices, and more.\nThis data includes data such as recall enforcement reports, adverse events, manufacturer details, and -- again -- even more!\nNote that the data on openFDA has not been validated for clinical or production use.\n\n## Installation\n\nThe easiest way to install openFDA is to get it from CRAN.\nHowever, given a spate of recent improvements which are not yet on CRAN, you may have a better time using the development version.\nNonetheless, to install from CRAN:\n```r\ninstall.packages(\"openFDA\")\n```\n\n### Development version\n```r\n# install.packages(\"pak\")\npak::pkg_install(\"simpar1471/openFDA\")\n```\n\n## Using openFDA\n```{r load_openFDA}\nlibrary(openFDA)\n```\n\nThe full documentation for the API is online, so look at the [openFDA \nwebsite](https://open.fda.gov/apis/) to get a full feel for the API itself.\n\nBefore using the package, you will need to generate an API key on the [openFDA website](https://open.fda.gov/apis/authentication/).\nWith 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).\nWithout a key, you can only make 1000 requests a day.\nFor this package, if you try to run `openFDA()` without setting an API key, it will fail:\n\n```{r store_api_key, echo = FALSE, eval = TRUE}\nrlang::push_options(openFDA.paging = \"never\",\n                    openFDA.paging_verbosity = \"quiet\")\nencrypted_api_key \u003c- paste0(\"TEaDtqdFMq9_Montij5p9IY6T57IyqkbF8IYFVOpk-\",\n                            \"ttxotFUNdJSxgccAnkq4nQhplaf-r3deQ\")\ndecrypted_api_key \u003c- httr2::secret_decrypt(encrypted_api_key, \"OPENFDA_KEY\")\nsuppressWarnings(try(\n  keyring::key_delete(\"OPENFDA_KEY\", \"openFDA\", \"openFDA\"),\n  silent = TRUE)\n)\nsuppressWarnings(try(\n  keyring::key_delete(\"OPENFDA_KEY\", \"openFDA\"), silent = TRUE)\n)\n```\n\n```{r no_api_key, error = TRUE}\nsearch \u003c- openFDA(\n  search = \"openfda.generic_name:furosemide\",\n  limit = 5\n)\n```\n\nThat's not good.\nTo fix this error, get an API key from the webpage linked above.\nOnce you have your API key, use `set_api_key()` to store your API key.\nOnce you run this function, **openFDA** will 'know' your API key, even for future sessions:\n\n```{r setting_api_key_fake, echo = TRUE, eval = TRUE}\n# n.b. this API key is a fake, just for demonstration\nset_api_key(api_key = \"iHXeqlbXtlYEwX9MYLwyCBuiZxfn98Sj3oX2FNtSx\")\n```\n\n```{r setting_api_key_real, echo = FALSE, eval = TRUE, message = FALSE}\nset_api_key(api_key = decrypted_api_key)\n```\n\nLet's try using `openFDA()` again, now that you have an API key:\n\n```{r example1_query}\nsearch \u003c- openFDA(\n  search = \"openfda.generic_name:furosemide\",\n  limit = 5\n)\n\nsearch\n```\n\nThe 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.\n\n```{r example2_json}\njson \u003c- httr2::resp_body_json(search)\n\njson$results[[1]]$openfda$brand_name\njson$results[[1]]$openfda$pharm_class_epc\n```\n\nI've found [purrr](https://purrr.tidyverse.org/) to be very useful for parsing this data quickly.\n\n```{r example3_purrr}\npurrr::map_chr(\n  .x = json$results, \n  .f = \\(result) purrr::pluck(result, \"openfda\", \"manufacturer_name\", 1)\n)\n```\n\n## Other R packages for openFDA\n\nThe [openfda](https://github.com/rOpenHealth/openfda) package from `rOpenHealth` also wraps the openFDA API from R, and is available on GitHub.\nIt'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.\nIt 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.\n\nThere is also [FDAopenR](https://github.com/ck2136/FDAopenR/), which is all object-oriented.\nI couldn't quite wrap my head around it, but it all appears to be in working order!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpar1471%2Fopenfda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimpar1471%2Fopenfda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpar1471%2Fopenfda/lists"}