Skip to contents

Retrieves daily weather forecasts for one or more beaches. Use aemet_beaches() to obtain beach codes.

Usage

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

Arguments

x

A character vector of beach codes to extract. See aemet_beaches().

verbose

A logical value. If TRUE, displays information about the exchange between the client and server.

return_sf

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

extract_metadata

A logical value. If TRUE, returns a tibble describing the response fields. See get_metadata_aemet().

progress

A logical value. If TRUE, displays a cli::cli_progress_bar() unless verbose = TRUE.

Value

A tibble or a sf object.

API key

Queries to the AEMET OpenData API require an API key. Use aemet_api_key() to set it globally. 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)
glimpse(forecast_b)
#> Rows: 6
#> Columns: 36
#> $ elaborado                <dttm> 2026-06-24 08:50:18, 2026-06-24 08:50:18, 20…
#> $ id                       <chr> "0704001", "0704001", "0704001", "0704007", "…
#> $ localidad                <chr> "07040", "07040", "07040", "07040", "07040", 
#> $ fecha                    <date> 2026-06-24, 2026-06-25, 2026-06-26, 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> 110, 100, 100, 100, 100, 100
#> $ estadoCielo_descripcion2 <chr> "nuboso", "despejado", "despejado", "despejad…
#> $ viento_value             <lgl> NA, NA, NA, NA, NA, NA
#> $ viento_f1                <int> 210, 210, 210, 210, 210, 210
#> $ viento_descripcion1      <chr> "flojo", "flojo", "flojo", "flojo", "flojo", 
#> $ viento_f2                <int> 210, 210, 210, 210, 210, 210
#> $ viento_descripcion2      <chr> "flojo", "flojo", "flojo", "flojo", "flojo", 
#> $ 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> 32, 32, 31, 34, 34, 32
#> $ sTermica_value           <lgl> NA, NA, NA, NA, NA, NA
#> $ sTermica_valor1          <int> 470, 470, 470, 470, 470, 470
#> $ sTermica_descripcion1    <chr> "calor moderado", "calor moderado", "calor mo…
#> $ tAgua_value              <lgl> NA, NA, NA, NA, NA, NA
#> $ tAgua_valor1             <int> 27, 27, 28, 27, 27, 28
#> $ uvMax_value              <lgl> NA, NA, NA, NA, NA, NA
#> $ uvMax_valor1             <int> 9, 9, 10, 9, 9, 10
#> $ tagua_value              <lgl> NA, NA, NA, NA, NA, NA
#> $ tagua_valor1             <int> 27, 27, 28, 27, 27, 28
#> $ stermica_value           <lgl> NA, NA, NA, NA, NA, NA
#> $ stermica_valor1          <int> 470, 470, 470, 470, 470, 470
#> $ stermica_descripcion1    <chr> "calor moderado", "calor moderado", "calor mo…
#> $ tmaxima_value            <lgl> NA, NA, NA, NA, NA, NA
#> $ tmaxima_valor1           <int> 32, 32, 31, 34, 34, 32

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"
  )