Stores an AEMET API key on your local machine so it can be used without including it in your code.
Alternatively, set the key for the current session with
Sys.setenv(AEMET_API_KEY = "Your_Key"), equivalent to install = FALSE.
To store it permanently, add AEMET_API_KEY = "Your_Key" to .Renviron,
equivalent to install = TRUE.
Arguments
- apikey
A character vector of AEMET API keys. Acquire a key at https://opendata.aemet.es/centrodedescargas/inicio. You can install multiple API keys at once. See Details.
- overwrite
A logical value. If
TRUE, overwrites an existingAEMET_API_KEYenvironment variable.- install
A logical value. If
TRUE, installs the key on your local machine for use in future sessions. Defaults toFALSE.
Details
You can pass multiple apikey values as a character vector, such as
c(api1, api2). In this case, multiple AEMET_API_KEY values are stored.
In each subsequent API call, climaemet chooses the API key with
the highest remaining quota.
This is useful when performing batch queries to avoid API throttling.
API key
Queries to the AEMET OpenData API require an API key. Use aemet_api_key()
to set it globally. Query timeout can be controlled with
options(climaemet_timeout = 60) (default value). See
httr2::req_timeout() for details.
See also
AEMET API authentication:
aemet_detect_api_key()
Examples
# Do not run these examples.
if (FALSE) {
aemet_api_key("111111abc", install = TRUE)
# Check it with:
Sys.getenv("AEMET_API_KEY")
}
if (FALSE) {
# Overwrite an existing key:
aemet_api_key("222222abc", overwrite = TRUE, install = TRUE)
# Check it with:
Sys.getenv("AEMET_API_KEY")
}
