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 arguments 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-04-18, 2026-04-19, 2026-04-20, 2026-04-21, 2026-04-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> 20.8, 21.1, 21.8, 21.9, 20.7, 21.6, 20.6, 20.4
#> $ prec        <dbl> 0.0, 0.0, 0.0, 0.6, 0.0, 0.0, 0.0, 1.2
#> $ tmin        <dbl> 13.3, 13.9, 14.6, 13.9, 13.7, 15.1, 13.4, 14.8
#> $ horatmin    <time> 04:00:00, 05:40:00, 05:10:00, 05:20:00, 06:00:00, 05:10:00…
#> $ tmax        <dbl> 28.4, 28.3, 29.0, 29.9, 27.7, 28.0, 27.8, 25.9
#> $ horatmax    <time> 16:40:00, 15:10:00, 15:50:00, 14:30:00, 14:00:00, 14:00:00…
#> $ dir         <chr> "24", "23", "14", "23", "04", "23", "23", "24"
#> $ velmedia    <dbl> 1.9, 4.7, 2.5, 3.1, 1.9, 1.7, 1.7, 1.9
#> $ racha       <dbl> 10.8, 10.8, 5.8, 14.2, 8.3, 8.3, 7.2, 15.6
#> $ horaracha   <time> 21:30:00, 18:20:00, 00:30:00, 20:40:00, 22:10:00, 15:10:00…
#> $ sol         <dbl> 11.6, 10.7, 11.0, 9.8, NA, NA, NA, NA
#> $ presMax     <dbl> 990.3, 989.4, 985.9, 981.3, 942.0, 940.7, 937.6, 934.2
#> $ horaPresMax <chr> "08", "07", "00", "Varias", "09", "Varias", "Varias", "00"
#> $ presMin     <dbl> 985.6, 983.5, 979.0, 976.2, 938.6, 936.9, 933.2, 930.6
#> $ horaPresMin <chr> "16", "16", "Varias", "16", "17", "17", "18", "16"
#> $ hrMedia     <dbl> 48, 50, 48, 47, 39, 39, 38, 53
#> $ hrMax       <dbl> 80, 83, 76, 82, 69, 69, 72, 83
#> $ horaHrMax   <time> 05:40:00, 05:40:00, 04:00:00, 05:20:00, 05:50:00, 05:00:00…
#> $ hrMin       <dbl> 26, 31, 24, 25, 19, 21, 21, 26
#> $ horaHrMin   <chr> "17:10", "Varias", "16:20", "15:30", "15:10", "Varias", "…

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