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 string with start and end date. See Details.

verbose

Logical TRUE/FALSE. Provides information about the flow of information between the client and server.

return_sf

Logical TRUE or FALSE. Should the function return an sf spatial object? If FALSE (the default value) it returns a tibble. Note that you need to have the sf package installed.

extract_metadata

Logical TRUE/FALSE. On TRUE the output is a tibble with the description of the fields. See also get_metadata_aemet().

progress

Logical, display a cli::cli_progress_bar() object. If verbose = TRUE won't be displayed.

Value

A tibble or a sf object.

Details

start and end parameters should 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().

Examples


library(tibble)
obs <- aemet_daily_clim(c("9434", "3195"))
glimpse(obs)
#> Rows: 8
#> Columns: 25
#> $ fecha       <date> 2026-03-11, 2026-03-12, 2026-03-13, 2026-03-14, 2026-03-1…
#> $ 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> 10.6, 13.4, 14.6, 11.4, 10.7, 12.0, 12.4, 11.3
#> $ prec        <dbl> 0.0, 0.0, 0.8, 0.0, 0.0, 0.0, 0.0, 0.0
#> $ tmin        <dbl> 5.3, 6.5, 7.2, 7.0, 6.2, 6.1, 6.2, 8.9
#> $ horatmin    <chr> "06:30", "06:00", "06:20", "23:59", "Varias", "06:40", "07…
#> $ tmax        <dbl> 15.9, 20.2, 22.0, 15.7, 15.2, 17.8, 18.5, 13.7
#> $ horatmax    <time> 13:00:00, 16:10:00, 14:40:00, 00:00:00, 17:00:00, 16:10:00…
#> $ dir         <dbl> 25, 23, 27, 31, 16, 23, 22, 29
#> $ velmedia    <dbl> 2.2, 1.9, 1.7, 7.2, 1.4, 1.7, 1.9, 3.3
#> $ racha       <dbl> 6.7, 8.3, 10.0, 15.6, 4.4, 5.8, 8.9, 12.8
#> $ horaracha   <time> 21:00:00, 20:00:00, 22:00:00, 11:50:00, 13:10:00, 16:20:00…
#> $ sol         <dbl> 6.2, 10.8, 10.2, 5.6, NA, NA, NA, NA
#> $ presMax     <dbl> 996.9, 996.7, 991.4, 981.9, 947.9, 948.3, 944.5, 935.6
#> $ horaPresMax <chr> "23", "00", "00", "24", "23", "Varias", "00", "00"
#> $ presMin     <dbl> 993.0, 991.4, 979.6, 977.5, 943.9, 944.3, 935.6, 930.1
#> $ horaPresMin <chr> "01", "24", "24", "15", "00", "24", "24", "16"
#> $ hrMedia     <dbl> 73, 69, 60, 68, 78, 64, 66, 61
#> $ hrMax       <dbl> 97, 94, 97, 92, NA, 90, 94, 74
#> $ horaHrMax   <chr> "06:50", "06:10", "06:30", "Varias", NA, "06:10", "07:00",
#> $ hrMin       <dbl> 54, 47, 34, 53, NA, 43, 44, 46
#> $ horaHrMin   <time> 16:40:00, 16:10:00, 15:30:00, 11:50:00,       NA, 13:40:00…

# 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…