This package maintains an internal set of API keys which users can set using setAPIKey(). These keys will be remembered for the duration of an R session. In functions that accept an API key argument, if the passed in API key is NULL, code will look up a specific named API key to see if that key has been set globally. Setting keys globally is a convenience that simplifies the scripts written by end users.

Currently supported API keys and associated functions include:

Arguments

provider

Character string used to identify an API key. Used as the first argument to setAPIKey() and getAPIKey().

key

Character API key. Used as the second argument to setAPIKey().

Value

An API key string or a list of provider:key pairs.

Details

Three API key support functions are imported from the MazamaCoreUtils package where they are described in more detail:

Examples

library(AirSensor)

# Start out with no keys (unless the user has set them)
showAPIKeys()
#>  list()
getAPIKey("PurpleAir-read")
#> NULL

# Set specific keys
setAPIKey("PurpleAir-read", "PURPLE_AIR_API_READ_KEY")
setAPIKey("PurpleAir-write", "PURPLE_AIR_API_WRITE_KEY")
showAPIKeys()
#> List of 2
#>  $ PurpleAir-read : chr "PURPLE_AIR_API_READ_KEY"
#>  $ PurpleAir-write: chr "PURPLE_AIR_API_WRITE_KEY"
getAPIKey("PurpleAir-read")
#> [1] "PURPLE_AIR_API_READ_KEY"

# Reset the read key
setAPIKey("PurpleAir-read", NULL)
showAPIKeys()
#> List of 1
#>  $ PurpleAir-write: chr "PURPLE_AIR_API_WRITE_KEY"
getAPIKey("PurpleAir-read")
#> NULL

# Reset the write key
setAPIKey("PurpleAir-write", NULL)
showAPIKeys()
#>  Named list()