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-04-30, 2025-05-01, 2025-05-02, 2025-05-03, 2025-04-3…
#> $ 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> 17.2, 19.5, 16.6, 18.8, 16.0, 16.7, 15.0, 15.8
#> $ prec        <dbl> 0.0, 0.0, 8.8, 2.2, 5.3, 22.7, 13.6, 0.9
#> $ tmin        <dbl> 11.7, 13.1, 13.3, 10.8, 11.4, 11.7, 10.5, 11.2
#> $ horatmin    <chr> "03:40", "Varias", "23:40", "05:20", "05:50", "00:50", "07…
#> $ tmax        <dbl> 22.8, 25.9, 20.0, 26.8, 20.5, 21.7, 19.5, 20.4
#> $ horatmax    <time> 15:10:00, 15:20:00, 12:40:00, 16:30:00, 16:10:00, 16:50:00…
#> $ dir         <chr> "11", "13", "11", "16", "30", "05", "09", "04"
#> $ velmedia    <dbl> 6.7, 5.8, 4.4, 1.7, 3.3, 1.4, 2.8, 1.7
#> $ racha       <dbl> 16.4, 15.6, 16.7, 11.7, 12.8, 6.4, 11.9, 12.2
#> $ horaracha   <time> 16:40:00, 17:00:00, 12:30:00, 16:40:00, 20:30:00, 23:59:00…
#> $ sol         <dbl> 11.5, 10.9, 2.6, 9.6, NA, NA, NA, NA
#> $ presMax     <dbl> 989.0, 988.0, 986.2, 985.5, 939.0, 938.8, 937.5, 938.2
#> $ horaPresMax <chr> "07", "01", "00", "07", "08", "01", "09", "Varias"
#> $ presMin     <dbl> 984.5, 983.5, 982.7, 980.5, 933.6, 934.2, 932.7, 935.4
#> $ horaPresMin <chr> "17", "17", "12", "16", "17", "19", "05", "17"
#> $ hrMedia     <dbl> 61, 53, 76, 73, 60, 71, 80, 65
#> $ hrMax       <dbl> 91, 81, 97, 99, 99, NA, NA, 97
#> $ horaHrMax   <chr> "Varias", "06:10", "Varias", "Varias", "23:20", NA, NA, "0…
#> $ hrMin       <dbl> 41, 34, 64, 38, 49, NA, NA, 41
#> $ horaHrMin   <time> 15:00:00, 16:50:00, 02:00:00, 15:50:00, 16:00:00,       NA

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