Skip to contents

Get climatology values for a station or for all the available stations. Note that aemet_daily_period() and aemet_daily_period_all() are shortcuts of aemet_daily_clim().

Usage

aemet_daily_clim(
  station = "all",
  start = Sys.Date() - 7,
  end = Sys.Date(),
  verbose = FALSE,
  return_sf = FALSE,
  extract_metadata = FALSE,
  progress = TRUE
)

aemet_daily_period(
  station,
  start = as.integer(format(Sys.Date(), "%Y")),
  end = start,
  verbose = FALSE,
  return_sf = FALSE,
  extract_metadata = FALSE,
  progress = TRUE
)

aemet_daily_period_all(
  start = as.integer(format(Sys.Date(), "%Y")),
  end = start,
  verbose = FALSE,
  return_sf = FALSE,
  extract_metadata = FALSE,
  progress = TRUE
)

Arguments

station

Character string with station identifier code(s) (see aemet_stations()) or "all" for all the stations.

start, end

Character strings with start and end dates. See Details.

verbose

Logical. If TRUE, provides information about the flow of information between the client and server.

return_sf

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

extract_metadata

Logical. If TRUE, the output is a tibble with the description of the fields. See also get_metadata_aemet().

progress

Logical. Displays a cli::cli_progress_bar() object. If verbose = TRUE, it will not be displayed.

Value

A tibble or a sf object.

Details

start and end arguments must be:

  • For aemet_daily_clim(): A Date object or a string with format YYYY-MM-DD ("2020-12-31") coercible with as.Date().

  • For aemet_daily_period() and aemet_daily_period_all(): A string representing the year(s) to be extracted: "2020", "2018".

API key

You need to set your API key globally using aemet_api_key(). Query timeout can be controlled with options(climaemet_timeout = 60) (default value). See httr2::req_timeout() for details.

Examples


library(tibble)
obs <- aemet_daily_clim(c("9434", "3195"))
glimpse(obs)
#> Rows: 8
#> Columns: 25
#> $ fecha       <date> 2026-06-01, 2026-06-02, 2026-06-03, 2026-06-04, 2026-06-0…
#> $ indicativo  <chr> "9434", "9434", "9434", "9434", "3195", "3195", "3195", "3…
#> $ nombre      <chr> "ZARAGOZA, AEROPUERTO", "ZARAGOZA, AEROPUERTO", "ZARAGOZA,…
#> $ provincia   <chr> "ZARAGOZA", "ZARAGOZA", "ZARAGOZA", "ZARAGOZA", "MADRID", 
#> $ altitud     <dbl> 249, 249, 249, 249, 667, 667, 667, 667
#> $ tmed        <dbl> 25.0, 22.4, 22.9, 21.4, 28.0, 25.0, 23.5, 23.8
#> $ prec        <dbl> 0, 0, 0, 0, 0, 0, 0, 0
#> $ tmin        <dbl> 16.8, 17.6, 15.8, 15.4, 21.1, 20.4, 16.5, 18.4
#> $ horatmin    <chr> "04:20", "23:50", "Varias", "23:30", "05:50", "23:59", "06…
#> $ tmax        <dbl> 33.1, 27.1, 30.0, 27.4, 34.9, 29.5, 30.5, 29.1
#> $ horatmax    <time> 16:30:00, 14:10:00, 16:50:00, 11:40:00, 14:30:00, 13:00:00…
#> $ dir         <dbl> 28, 32, 32, 34, 99, 15, 14, 15
#> $ velmedia    <dbl> 3.1, 7.8, 6.4, 6.4, 2.8, 3.1, 1.7, 3.1
#> $ racha       <dbl> 12.8, 15.0, 15.8, 15.0, 11.1, 10.6, 8.3, 11.1
#> $ horaracha   <time> 00:10:00, 19:50:00, 11:10:00, 13:20:00, 17:40:00, 13:30:00…
#> $ sol         <dbl> 12.0, 12.3, 14.2, 7.7, NA, NA, NA, NA
#> $ presMax     <dbl> 988.7, 989.8, 990.0, 987.2, 940.4, 940.2, 942.5, 937.3
#> $ horaPresMax <chr> "00", "22", "07", "24", "08", "23", "09", "00"
#> $ presMin     <dbl> 981.8, 983.0, 982.9, 981.2, 936.3, 937.4, 937.3, 934.4
#> $ horaPresMin <chr> "18", "01", "24", "12", "17", "Varias", "24", "16"
#> $ hrMedia     <dbl> 28, 45, 40, 52, 30, 34, 39, 36
#> $ hrMax       <dbl> 54, 67, 63, 74, 53, 55, 67, 72
#> $ horaHrMax   <time> 23:30:00, 02:50:00, 04:30:00, 05:00:00, 05:30:00, 05:00:00…
#> $ hrMin       <dbl> 17, 39, 29, 37, 13, 22, 23, 18
#> $ horaHrMin   <chr> "14:00", "Varias", "12:00", "13:30", "14:40", "Varias", "1…

# Metadata
meta <- aemet_daily_clim(c("9434", "3195"), extract_metadata = TRUE)

glimpse(meta$campos)
#> Rows: 25
#> Columns: 5
#> $ id          <chr> "fecha", "indicativo", "nombre", "provincia", "altitud", "…
#> $ descripcion <chr> "fecha del dia (AAAA-MM-DD)", "indicativo climatológico", 
#> $ tipo_datos  <chr> "string", "string", "string", "string", "float", "float", 
#> $ requerido   <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, 
#> $ unidad      <chr> NA, NA, NA, NA, "m", "°C", "mm (Ip = inferior a 0,1 mm) (A…