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> 2025-06-18, 2025-06-19, 2025-06-20, 2025-06-21, 2025-06-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> 28.6, 30.2, 29.6, 31.6, 29.9, 28.9, 29.7, 30.7
#> $ prec        <chr> "0,0", "0,0", "0,0", "Ip", "0,0", "0,0", "0,0", "0,0"
#> $ tmin        <dbl> 20.2, 22.1, 20.7, 23.6, 22.2, 22.6, 22.4, 23.5
#> $ horatmin    <time> 04:40:00, 04:30:00, 04:50:00, 04:50:00, 05:20:00, 06:00:00…
#> $ tmax        <dbl> 37.0, 38.2, 38.4, 39.6, 37.6, 35.2, 37.0, 37.9
#> $ horatmax    <chr> "16:30", "15:10", "16:40", "14:50", "14:40", "12:30", "Var…
#> $ dir         <chr> "31", "32", "32", "25", "02", "32", "10", "29"
#> $ velmedia    <dbl> 2.2, 6.1, 3.1, 4.7, 1.9, 2.2, 1.4, 2.2
#> $ racha       <dbl> 6.9, 20.0, 7.5, 18.9, 7.8, 10.6, 11.1, 15.6
#> $ horaracha   <time> 01:20:00, 17:50:00, 00:10:00, 18:20:00, 18:30:00, 14:30:00…
#> $ sol         <dbl> 13.3, 10.1, 13.8, 10.8, NA, NA, NA, NA
#> $ presMax     <dbl> 992.0, 991.0, 991.1, 989.7, 944.2, 945.3, 945.3, 942.5
#> $ horaPresMax <chr> "08", "21", "07", "23", "08", "24", "00", "00"
#> $ presMin     <dbl> 986.7, 985.9, 986.2, 983.7, 941.0, 942.5, 940.5, 938.3
#> $ horaPresMin <chr> "18", "15", "18", "17", "Varias", "03", "17", "18"
#> $ hrMedia     <dbl> 36, 42, 34, 32, 32, 31, 32, 28
#> $ hrMax       <dbl> 66, 72, 70, 68, 57, 58, 54, 51
#> $ horaHrMax   <time> 05:00:00, 04:20:00, 05:40:00, 04:40:00, 02:30:00, 05:40:00…
#> $ hrMin       <dbl> 20, 23, 14, 15, 16, 19, 17, 15
#> $ horaHrMin   <chr> "13:30", "14:50", "Varias", "Varias", "14:50", "13:50", "…

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