Client tool to get data and metadata from AEMET and convert json to tibble.
Arguments
- apidest
Character string as destination URL. See https://opendata.aemet.es/dist/index.html.
- verbose
Logical
TRUE/FALSE. Provides information about the flow of information between the client and server.
Value
A tibble (if possible) or the results of the query as
provided by httr2::resp_body_raw() or httr2::resp_body_string().
See also
Some examples on how to use these functions on
vignette("extending-climaemet").
Examples
# Run this example only if AEMET_API_KEY is detected
url <- "/api/valores/climatologicos/inventarioestaciones/todasestaciones"
get_data_aemet(url)
#> # A tibble: 947 × 7
#> latitud provincia altitud indicativo nombre indsinop longitud
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 394924N ILLES BALEARS 490 B013X ESCORCA, LLUC "08304" 025309E
#> 2 394744N BALEARES 5 B051A SÓLLER, PUERTO "08316" 024129E
#> 3 394121N ILLES BALEARS 60 B087X BANYALBUFAR "" 023046E
#> 4 393446N BALEARES 52 B103B ANDRATX - SANT ELM "" 022208E
#> 5 393305N BALEARES 50 B158X CALVIÀ, ES CAPDEL… "" 022759E
#> 6 393315N ILLES BALEARS 3 B228 PALMA, PUERTO "08301" 023731E
#> 7 393832N ILLES BALEARS 95 B236C PALMA, UNIVERSITAT "" 023838E
#> 8 394406N ILLES BALEARS 1030 B248 SIERRA DE ALFABIA… "08303" 024247E
#> 9 393621N BALEARES 47 B275E SON BONET, AEROPU… "08302" 024224E
#> 10 393339N BALEARES 5 B278 PALMA DE MALLORCA… "08306" 024412E
#> # ℹ 937 more rows
# Metadata
get_metadata_aemet(url)
#> # A tibble: 7 × 7
#> unidad_generadora periodicidad descripcion formato copyright notaLegal
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 2 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 3 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 4 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 5 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 6 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 7 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> # ℹ 1 more variable: campos <df[,4]>
# We can get data from any API endpoint
# Plain text
plain <- get_data_aemet("/api/prediccion/nacional/hoy")
#> ℹ Results are MIME type: "text/plain".
#> → Returning data as UTF-8 string.
cat(plain)
#> AGENCIA ESTATAL DE METEOROLOGÍA
#> PREDICCIÓN GENERAL PARA ESPAÑA
#> DÍA 29 DE ENERO DE 2026 A LAS 13:40 HORA OFICIAL
#> PREDICCIÓN VÁLIDA PARA EL JUEVES 29
#>
#> A.- FENÓMENOS SIGNIFICATIVOS
#> Probables precipitaciones persistentes en zonas de sierra del
#> sureste peninsular. Rachas muy fuertes de viento de componente
#> oeste en el extremo noroeste peninsular, litorales del
#> Cantábrico, Estrecho, Alborán, montañas del centro y sur y en
#> amplias zonas del tercio oriental. Ascenso notable de las
#> temperaturas máximas en amplias zonas de la mitad norte
#> peninsular.
#>
#> B.- PREDICCIÓN
#> Persistirá la circulación atlántica, con el paso de un frente
#> dejando cielos nubosos o cubiertos y precipitaciones generalizadas
#> en la Península y Baleares, si bien siendo menos probables e
#> intensas en la fachada oriental y extremo nordeste peninsular,
#> así como en el norte de Baleares y Melilla. Por el contrario, los
#> mayores acumulados se darán en Galicia, montañas de la vertiente
#> atlántica y, con probabilidad de ser persistentes, en las del
#> sureste peninsular. En la segunda mitad del día las
#> precipitaciones tenderán a menos y se abrirán algunos claros,
#> exceptuando en el sur peninsular así como en el cuadrante
#> noroeste y Cantábrico, donde un nuevo frente mantendrá las
#> precipitaciones, siendo posible que fueran acompañadas localmente
#> de tormenta y granizo. Nevará en montañas del centro y mitad
#> norte con una cota de 1000/1200 m subiendo a 1500/1700 m en el
#> entorno pirenaico, de 1300/1500 m subiendo por encima de 1800 m en
#> el resto de cuadrante nordeste y centro norte, y bajando de 2000 m
#> hasta los 1300/1500 en el noroeste. Cielos poco nubosos en
#> Canarias.
#>
#> Las temperaturas ascenderán de forma prácticamente generalizada
#> en la Península y Baleares, exceptuando las mínimas en Cataluña
#> y las máximas en cuadrante suroeste con pocos cambios. Los
#> ascensos llegarán a notables en las máximas en amplias zonas de
#> la mitad norte peninsular. Pocos cambios en Canarias. Heladas
#> débiles en cotas altas de la mitad norte peninsular, más
#> extensas e intensas en el Pirineo..
#>
#> Predominará el viento moderado de componente oeste en la
#> Península y Baleares, llegando a fuerte con rachas muy fuertes en
#> el extremo noroeste peninsular, litorales del Cantábrico,
#> Baleares, Estrecho, Alborán, montañas del centro y de Andalucía
#> y amplias zonas del tercio oriental peninsular, siendo posible
#> también en puntos de ambas mesetas, y pudiendo llegar a
#> localmente huracanado en las sierras del extremo sureste. Viento
#> flojo de oeste en Canarias rolando a norte moderado.
#>
# An image
image <- get_data_aemet("/api/mapasygraficos/analisis")
#> ℹ Results are MIME type: "image/gif".
#> → Returning <raw> bytes. See also `base::writeBin()`.
# Write and read
tmp <- tempfile(fileext = ".gif")
writeBin(image, tmp)
gganimate::gif_file(tmp)
#> Error in shell.exec(url): file association for 'C:\Users\RUNNER~1\AppData\Local\Temp\Rtmpk9Cnfl\file1008294b4071.gif' not available or invalid
