Skip to contents

Get and set your openFDA API keys

Usage

set_api_key(api_key)

get_api_key()

Arguments

api_key

A single-length character vector with your openFDA API key. You can generate an API key on the FDA website.

Value

A single length character vector with your API key. For set_api_key(), this is returned invisibly.

For get_api_key(), an error will be thrown if no key has been set.

Note

To permanently set the API key for a given project, set OPENFDA_TOKEN in .Renviron.

Examples

# Set your openFDA API key with `set_api_key()`
api_key <- "example_api_key"
set_api_key(api_key)

# Retrieve it with `get_api_key()`
get_api_key()
#> [1] "example_api_key"

# An error will be thrown if your API key is an empty string.
set_api_key("")

try(get_api_key())
#> Error in get_api_key() : 
#>   To use openFDA, you must set an openFDA API key.
#>  Go to <https://open.fda.gov/apis/authentication/> to get an openFDA API key,
#>   then supply it to `set_api_key()` to cache it for use in this session.