Skip to contents

Retrieves the weather stations available from the AEMET API.

Usage

aemet_stations(verbose = FALSE, return_sf = FALSE)

Arguments

verbose

A logical value. If TRUE, displays information about the exchange between the client and server.

return_sf

A logical value. If TRUE, the function returns an sf spatial object. If FALSE (the default), it returns a tibble. The sf package must be installed.

Value

A tibble or a sf object.

Note

Code modified from project https://github.com/SevillaR/aemet.

Caching

The first result retrieved in each session is temporarily cached in tempdir() to avoid unnecessary requests.

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.

Examples

library(dplyr)
stations <- aemet_stations()
#> Error in httr2::req_perform(req1): Failed to perform HTTP request.
#> Caused by error in `curl::curl_fetch_memory()`:
#> ! Timeout was reached [opendata.aemet.es]:
#> Connection timed out after 60002 milliseconds
stations
#> Error: object 'stations' not found

# Cached during this R session.
stations2 <- aemet_stations(verbose = TRUE)
#> 
#> ── climaemet: API call ─────────────────────────────────────────────────────────
#>  Using API key "XXXX...eijBsae3gA4".
#>  Requesting <https://opendata.aemet.es/opendata/api/valores/climatologicos/inventarioestaciones/todasestaciones>.
#>  HTTP `200`: exito
#>  Remaining request count: "149".
#> 
#> ── Requesting data ──
#> 
#>  Requesting <https://opendata.aemet.es/opendata/sh/e00ed1f6>.
#>  HTTP `200`: Se han encontrado 920 estaciones
#>  Remaining request count: "148".
#> 

identical(stations, stations2)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'identical': object 'stations' not found