Convenient access to the OpenFDA API
R
Switch branches/tags
Nothing to show
Clone or download
Latest commit ace7ef9 Nov 2, 2015
Permalink
Failed to load latest commit information.
R
inst
man
tests
.Rbuildignore
.gitignore doc updates and R CMD check fixes Mar 3, 2015
DESCRIPTION
NAMESPACE
README.Rmd
README.md document move to rOpenHealth Mar 4, 2015

README.md

openfda

Convenient access to the OpenFDA API

This package provides some simple helpers for accessing the OpenFDA API from R. It uses the jsonlite and magrittr packages to provide a simple way to convert from OpenFDA queries to R dataframes suitable for quick analysis and plotting.

Installation

This library has not yet been added to CRAN, so you'll need the devtools package to install it:

install.packages("devtools")

Once devtools is installed, you can grab this package:

library("devtools")
devtools::install_github("ropenhealth/openfda")

Load it in like any other package:

library("openfda")

Examples

patient_ages = fda_query("/drug/event.json") %>%
               fda_count("patient.patientonsetage") %>%
               fda_exec()
## Fetching: https://api.fda.gov/drug/event.json?search=&count=patient.patientonsetage
# patient ages is now a data frame with "term" and "count" columns
# let's plot it with ggplot2
library("ggplot2")
qplot(x=term, y=count, data=patient_ages)

plot of chunk unnamed-chunk-3

You can filter the results to count on using the fda_filter() method:

paxil_ages = fda_query("/drug/event.json") %>%
               fda_filter("patient.drug.openfda.generic_name", "paroxetine") %>%
               fda_count("patient.patientonsetage") %>%
               fda_exec()

Using this API with your API key is easy: just add fda_api_key("MY_KEY") to your pipeline.

patient_ages = fda_query("/drug/event.json") %>%
               fda_api_key("MYKEY") %>%
               fda_count("patient.patientonsetage") %>%
               fda_exec()

You can also specify options up front and re-use the query:

age_query = fda_query("/drug/event.json") %>%
            fda_api_key("MYKEY") %>%
            fda_count("patient.patientonsetage");

paxil_ages = age_query %>% fda_filter("patient.drug.openfda.generic_name", "paroxetine") %>% fda_exec()
zoloft_ages = age_query %>% fda_filter("patient.drug.openfda.generic_name", "sertraline") %>% fda_exec()

R documentation for each method is also provided in the package (? fda_exec).