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. sf 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)
#>  HTTP status 404:
#>   Error al obtener los datos
#> ! AEMET OpenData API request for "0704001" returned an error.
#>  Returning "NULL" for this request.
#>  HTTP status 404:
#>   Error al obtener los datos
#> ! AEMET OpenData API request for "0704007" returned an error.
#>  Returning "NULL" for this request.
#> Warning: Unknown or uninitialised column: `id`.
glimpse(forecast_b)
#> Rows: 0
#> Columns: 1
#> $ id <chr> 

ggplot(forecast_b) +
  geom_line(aes(fecha, tagua_valor1, color = nombre)) +
  facet_wrap(~nombre, ncol = 1) +
  labs(
    title = "Water temperature at beaches in Palma (ES)",
    subtitle = "3-day forecast",
    x = "Date",
    y = "Temperature (Celsius)",
    color = "Beach"
  )
#> Error in combine_vars(data, params$plot_env, vars, drop = params$drop): At least one layer must contain all faceting variables: `nombre`
#>  Plot is missing `nombre`
#>  Layer 1 is missing `nombre`