Skip to contents

Retrieves weather forecast data from the Norwegian Meteorological Institute locationforecast API and returns the parsed metadata together with a tidy hourly data.table. The response headers Expires and Last-Modified are provided both in their raw RFC 1123 form and parsed to POSIXct for downstream logic.

Usage

get_metno_forecast(
  latitude,
  longitude,
  format = c("compact", "complete"),
  api_key = get_key(service = "METNO"),
  timeout = 30,
  max_retries = 3,
  retry_delay = 1
)

Arguments

latitude

Numeric. Latitude in decimal degrees for the forecast location. Must be within Australian limits (-44 to -10).

longitude

Numeric. Longitude in decimal degrees for the forecast location. Must be within Australian limits (112 to 154).

format

Character. Either "compact" (default) or "complete" for the MET Weather API locationforecast endpoint variant.

api_key

Character. Email address required for the User-Agent header in accordance with MET Weather API terms of service.

timeout

Numeric. Request timeout in seconds (default: 30).

max_retries

Integer. Maximum number of retry attempts on transient failures (default: 3).

retry_delay

Numeric. Base delay between retries in seconds for exponential backoff (default: 1).

Value

A named list with elements:

data

Hourly forecast as a data.table.

raw

The full parsed GeoJSON response (list).

metadata

A list containing request parameters, status code, retrieval timestamp, and header information (expires_raw, expires, last_modified_raw, last_modified).

Author

Rodrigo Pires, rodrigo.pires@dpird.wa.gov.au

Examples

if (FALSE) { # \dontrun{
forecast <- get_metno_forecast(
  latitude = -31.95,
  longitude = 115.86,
  api_key = "your.email@example.com"
)
forecast$metadata$expires
utils::head(forecast$data)
} # }