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, it will not 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: 10
#> Columns: 25
#> $ fecha       <date> 2026-05-11, 2026-05-12, 2026-05-13, 2026-05-14, 2026-05-1…
#> $ indicativo  <chr> "9434", "9434", "9434", "9434", "9434", "3195", "3195", "3…
#> $ nombre      <chr> "ZARAGOZA, AEROPUERTO", "ZARAGOZA, AEROPUERTO", "ZARAGOZA,…
#> $ provincia   <chr> "ZARAGOZA", "ZARAGOZA", "ZARAGOZA", "ZARAGOZA", "ZARAGOZA"…
#> $ altitud     <dbl> 249, 249, 249, 249, 249, 667, 667, 667, 667, 667
#> $ tmed        <dbl> 17.3, 16.5, 15.4, 15.3, 13.4, 13.4, 14.2, 14.8, 16.8, 13.3
#> $ prec        <dbl> 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.0, 0.0, 0.4
#> $ tmin        <dbl> 9.9, 11.3, 10.6, 11.0, 9.6, 8.6, 10.1, 10.0, 11.9, 10.0
#> $ horatmin    <time> 04:20:00, 05:10:00, 05:00:00, 03:30:00, 23:59:00, 05:50:00…
#> $ tmax        <dbl> 24.7, 21.7, 20.1, 19.6, 17.2, 18.1, 18.4, 19.7, 21.7, 16.6
#> $ horatmax    <time> 15:50:00, 14:30:00, 14:10:00, 13:00:00, 14:40:00, 16:10:00…
#> $ dir         <chr> "30", "28", "31", "32", "32", "09", "12", "14", "99", "23"
#> $ velmedia    <dbl> 3.9, 6.7, 7.5, 5.3, 8.9, 1.9, 2.5, 2.2, 3.6, 3.3
#> $ racha       <dbl> 12.8, 13.9, 16.4, 13.1, 18.3, 8.1, 11.9, 8.6, 10.3, 11.7
#> $ horaracha   <chr> "17:20", "14:50", "09:50", "12:30", "16:00", "13:40", "13:…
#> $ sol         <dbl> 9.7, 10.4, 13.1, 5.3, 10.4, NA, NA, NA, NA, NA
#> $ presMax     <dbl> 985.7, 986.4, 987.2, 985.2, 985.2, 938.8, 940.2, 940.2, 93…
#> $ horaPresMax <chr> "24", "24", "07", "00", "Varias", "12", "23", "10", "00",
#> $ presMin     <dbl> 981.9, 983.1, 984.7, 977.1, 975.2, 935.7, 937.5, 937.1, 92…
#> $ horaPresMin <chr> "16", "14", "Varias", "24", "04", "02", "03", "18", "18",
#> $ hrMedia     <dbl> 55, 58, 48, 51, 54, 68, 68, 63, 45, 57
#> $ hrMax       <dbl> 94, 89, 76, 75, 78, 97, 92, 89, 77, 78
#> $ horaHrMax   <chr> "05:20", "04:30", "04:40", "03:20", "01:00", "05:30", "05:…
#> $ hrMin       <dbl> 30, 36, 40, 35, 37, 47, 52, 44, 28, 30
#> $ horaHrMin   <chr> "15:30", "15:40", "12:20", "12:30", "14:00", "16:30", "13:…

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