Skip to contents

Get daily weather forecasts for one or more beaches. Beach codes can be accessed with aemet_beaches().

Usage

aemet_forecast_beaches(
  x,
  verbose = FALSE,
  return_sf = FALSE,
  extract_metadata = FALSE,
  progress = TRUE
)

Arguments

x

Character vector with beach codes to extract. See aemet_beaches().

verbose

Logical. If TRUE, provides information about the flow of information between the client and server.

return_sf

Logical. If TRUE, the function returns an sf spatial object. If FALSE (the default value), it returns a tibble. The sf package must be installed.

extract_metadata

Logical. If TRUE, the output is a tibble with the description of the fields. See also get_metadata_aemet().

progress

Logical. Displays a cli::cli_progress_bar() object. If verbose = TRUE, it will not be displayed.

Value

A tibble or a sf object.

API key

You need to set your API key globally using aemet_api_key(). Query timeout can be controlled with options(climaemet_timeout = 60) (default value). See httr2::req_timeout() for details.

Examples

# Forecast for beaches in Palma, Mallorca
library(dplyr)
library(ggplot2)

palma_b <- aemet_beaches() |>
  filter(ID_MUNICIPIO == "07040")

forecast_b <- aemet_forecast_beaches(palma_b$ID_PLAYA)
#> ! HTTP 429:
#>   Límite de peticiones o caudal por minuto excedido para este usuario. Espere
#>   al siguiente minuto.
#>  Retrying.
#> Waiting 4s for retry backoff ■■■■■■■■■                       
#> Waiting 4s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■■        
#> Waiting 4s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 
#> Waiting 7s for retry backoff ■■■■■■■■■                       
#> Waiting 7s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■         
#> Waiting 7s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 
#> 
glimpse(forecast_b)
#> Rows: 6
#> Columns: 36
#> $ elaborado                <dttm> 2026-06-08 05:50:17, 2026-06-08 05:50:17, 20…
#> $ id                       <chr> "0704001", "0704001", "0704001", "0704007", "…
#> $ localidad                <chr> "07040", "07040", "07040", "07040", "07040", 
#> $ fecha                    <date> 2026-06-08, 2026-06-09, 2026-06-10, 2026-06-…
#> $ nombre                   <chr> "Cala Major", "Cala Major", "Cala Major", "Pl…
#> $ estadoCielo_value        <lgl> NA, NA, NA, NA, NA, NA
#> $ estadoCielo_f1           <int> 100, 100, 100, 100, 100, 100
#> $ estadoCielo_descripcion1 <chr> "despejado", "despejado", "despejado", "despe…
#> $ estadoCielo_f2           <int> 100, 100, 100, 100, 100, 100
#> $ estadoCielo_descripcion2 <chr> "despejado", "despejado", "despejado", "despe…
#> $ viento_value             <lgl> NA, NA, NA, NA, NA, NA
#> $ viento_f1                <int> 210, 220, 210, 210, 220, 220
#> $ viento_descripcion1      <chr> "flojo", "moderado", "flojo", "flojo", "moder…
#> $ viento_f2                <int> 210, 210, 220, 210, 220, 220
#> $ viento_descripcion2      <chr> "flojo", "flojo", "moderado", "flojo", "moder…
#> $ oleaje_value             <lgl> NA, NA, NA, NA, NA, NA
#> $ oleaje_f1                <int> 310, 310, 310, 310, 310, 310
#> $ oleaje_descripcion1      <chr> "débil", "débil", "débil", "débil", "débil", 
#> $ oleaje_f2                <int> 310, 310, 310, 310, 310, 310
#> $ oleaje_descripcion2      <chr> "débil", "débil", "débil", "débil", "débil", 
#> $ tMaxima_value            <lgl> NA, NA, NA, NA, NA, NA
#> $ tMaxima_valor1           <int> 28, 28, 28, 29, 29, 28
#> $ sTermica_value           <lgl> NA, NA, NA, NA, NA, NA
#> $ sTermica_valor1          <int> 460, 460, 460, 460, 460, 460
#> $ sTermica_descripcion1    <chr> "calor agradable", "calor agradable", "calor …
#> $ tAgua_value              <lgl> NA, NA, NA, NA, NA, NA
#> $ tAgua_valor1             <int> 24, 24, 24, 24, 22, 22
#> $ uvMax_value              <lgl> NA, NA, NA, NA, NA, NA
#> $ uvMax_valor1             <int> 9, 9, 8, 9, 9, 8
#> $ tagua_value              <lgl> NA, NA, NA, NA, NA, NA
#> $ tagua_valor1             <int> 24, 24, 24, 24, 22, 22
#> $ stermica_value           <lgl> NA, NA, NA, NA, NA, NA
#> $ stermica_valor1          <int> 460, 460, 460, 460, 460, 460
#> $ stermica_descripcion1    <chr> "calor agradable", "calor agradable", "calor …
#> $ tmaxima_value            <lgl> NA, NA, NA, NA, NA, NA
#> $ tmaxima_valor1           <int> 28, 28, 28, 29, 29, 28

ggplot(forecast_b) +
  geom_line(aes(fecha, tagua_valor1, color = nombre)) +
  facet_wrap(~nombre, ncol = 1) +
  labs(
    title = "Water temperature in beaches of Palma (ES)",
    subtitle = "3-day forecast",
    x = "Date",
    y = "Temperature (Celsius)",
    color = "Beach"
  )