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 ansfspatial object. IfFALSE(the default), it returns a tibble. sf must be installed.- extract_metadata
A logical value. If
TRUE, returns a tibble describing the response fields. Seeget_metadata_aemet().- progress
A logical value. If
TRUE, displays acli::cli_progress_bar()unlessverbose = TRUE.
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.
See also
aemet_beaches() for beach codes.
Forecasts:
aemet_forecast_daily(),
aemet_forecast_fires(),
aemet_forecast_tidy()
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`
