| Title: | Download and Read Brazilian Meteorological Data from INMET |
|---|---|
| Description: | Automates the download and processing of historical weather data from the Brazilian National Institute of Meteorology (INMET). It provides a cached catalogue of automatic stations, resumable and validated downloads, and parsers for formatting inconsistencies in raw CSV files across different years. It removes structural artifacts, standardizes column names, parses timestamps, and returns data frames ready for analysis. Data are retrieved from <https://portal.inmet.gov.br/dadoshistoricos> and <https://apitempo.inmet.gov.br/estacoes/T>. |
| Authors: | Rodrigo Fonseca Villa [aut, cre] (ORCID: <https://orcid.org/0009-0005-2938-2270>) |
| Maintainer: | Rodrigo Fonseca Villa <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.2.0 |
| Built: | 2026-09-19 20:55:23 UTC |
| Source: | https://github.com/rodrigosqrt3/rmet |
Clear the rmet cache
inmet_cache_clear( years = NULL, dest_dir = tools::R_user_dir("rmet", "cache"), ask = interactive(), catalog = FALSE )inmet_cache_clear( years = NULL, dest_dir = tools::R_user_dir("rmet", "cache"), ask = interactive(), catalog = FALSE )
years |
Integer years to remove, or |
dest_dir |
Cache directory. |
ask |
Ask for confirmation before deleting. |
catalog |
Also remove the cached official station catalogue. |
Invisible NULL.
Inspect downloaded INMET archives
inmet_cache_status(dest_dir = tools::R_user_dir("rmet", "cache"))inmet_cache_status(dest_dir = tools::R_user_dir("rmet", "cache"))
dest_dir |
Cache directory used by |
Invisibly, a data frame with archive year, path, size, validity, and whether a partial download exists.
Downloads one or more annual ZIP files from INMET's historical data portal.
Complete archives already in the cache are reused. Interrupted downloads are
kept in a .part file and resumed on the next attempt.
inmet_download( years = as.integer(format(Sys.Date(), "%Y")), dest_dir = tools::R_user_dir("rmet", "cache"), max_tries = 15L, quiet = FALSE, force = FALSE )inmet_download( years = as.integer(format(Sys.Date(), "%Y")), dest_dir = tools::R_user_dir("rmet", "cache"), max_tries = 15L, quiet = FALSE, force = FALSE )
years |
Integer vector of years to download. Available years start in 2000. Defaults to the current year. |
dest_dir |
Character. Cache directory. It is created when necessary. |
max_tries |
Positive integer. Maximum attempts per year. |
quiet |
Logical. Suppress progress messages. |
force |
Logical. Download again even when a valid archive is cached. |
Files are first written to <year>.zip.part. A partial file is never exposed
as a complete ZIP. After an integrity check succeeds, the file is atomically
moved to <year>.zip whenever the operating system permits it.
Invisibly, a named character vector containing the paths of all successfully downloaded archives.
inmet_read(), inmet_get(), inmet_extract()
paths <- inmet_download(2023, dest_dir = tempdir())paths <- inmet_download(2023, dest_dir = tempdir())
Extract INMET archives
inmet_extract( years, dest_dir = tools::R_user_dir("rmet", "cache"), out_dir = file.path(dest_dir, "csv"), overwrite = FALSE, quiet = FALSE )inmet_extract( years, dest_dir = tools::R_user_dir("rmet", "cache"), out_dir = file.path(dest_dir, "csv"), overwrite = FALSE, quiet = FALSE )
years |
Integer years to extract. |
dest_dir |
Directory containing annual ZIP files. |
out_dir |
Destination directory. |
overwrite |
Overwrite existing files. |
quiet |
Suppress progress messages. |
Invisibly, paths returned by utils::unzip().
This is the recommended high-level interface. It downloads missing annual
archives, reuses valid cached files, and returns the result of inmet_read().
inmet_get( years, stations = NULL, dest_dir = tools::R_user_dir("rmet", "cache"), tz = "UTC", variables = NULL, start_date = NULL, end_date = NULL, max_tries = 15L, force = FALSE, quiet = FALSE )inmet_get( years, stations = NULL, dest_dir = tools::R_user_dir("rmet", "cache"), tz = "UTC", variables = NULL, start_date = NULL, end_date = NULL, max_tries = 15L, force = FALSE, quiet = FALSE )
years |
Integer vector of years. |
stations |
Optional station codes. Matching is case-insensitive. |
dest_dir |
Directory containing |
tz |
Output time zone. Defaults to |
variables |
Optional meteorological columns to retain. |
start_date, end_date
|
Optional inclusive date limits in |
max_tries |
Maximum download attempts per year. |
force |
Download archives again even if they are valid. |
quiet |
Suppress progress messages. |
A data frame as documented in inmet_read().
weather <- inmet_get( years = 2023, stations = "A801", variables = c("temp_dry_c", "precip_mm"), dest_dir = tempdir() )weather <- inmet_get( years = 2023, stations = "A801", variables = c("temp_dry_c", "precip_mm"), dest_dir = tempdir() )
Parses CSV files inside annual INMET archives into a consistent data frame.
inmet_read( years, stations = NULL, dest_dir = tools::R_user_dir("rmet", "cache"), tz = "UTC", variables = NULL, start_date = NULL, end_date = NULL, quiet = FALSE )inmet_read( years, stations = NULL, dest_dir = tools::R_user_dir("rmet", "cache"), tz = "UTC", variables = NULL, start_date = NULL, end_date = NULL, quiet = FALSE )
years |
Integer vector of years. |
stations |
Optional station codes. Matching is case-insensitive. |
dest_dir |
Directory containing |
tz |
Output time zone. Defaults to |
variables |
Optional meteorological columns to retain. |
start_date, end_date
|
Optional inclusive date limits in |
quiet |
Suppress progress messages. |
A data frame. Identifier and station metadata columns are always retained when data are available.
inmet_get(), inmet_download(), inmet_stations()
df <- inmet_read(2023, stations = "A801", dest_dir = tempdir())df <- inmet_read(2023, stations = "A801", dest_dir = tempdir())
Returns automatic weather stations published by INMET. By default, the function uses a cached copy of the official API response and refreshes stale caches periodically. If the service is unavailable, it falls back to an older cache or to the smaller catalogue bundled with the package.
inmet_stations( region = NULL, state = NULL, search = NULL, status = NULL, entity = NULL, source = c("auto", "remote", "bundled"), refresh = FALSE, max_age = 30, cache_dir = tools::R_user_dir("rmet", "cache"), quiet = FALSE )inmet_stations( region = NULL, state = NULL, search = NULL, status = NULL, entity = NULL, source = c("auto", "remote", "bundled"), refresh = FALSE, max_age = 30, cache_dir = tools::R_user_dir("rmet", "cache"), quiet = FALSE )
region, state
|
Optional region or state abbreviations. |
search |
Optional literal text contained in the station name or code. |
status |
Optional operational status, such as |
entity |
Optional station owner/provider, such as |
source |
One of |
refresh |
Force a fresh request to the official API. |
max_age |
Maximum cache age in days before an automatic refresh. |
cache_dir |
Directory used for the catalogue cache. |
quiet |
Suppress informational messages. |
A data frame with station code, name, region, state, coordinates,
altitude, operational dates and status, and provider metadata. The legacy
start_year column is retained for compatibility.
# Offline, reproducible example using the bundled fallback inmet_stations(state = "RS", source = "bundled") # Current official catalogue (downloaded once and then cached) inmet_stations(state = "RS", refresh = TRUE, cache_dir = tempdir())# Offline, reproducible example using the bundled fallback inmet_stations(state = "RS", source = "bundled") # Current official catalogue (downloaded once and then cached) inmet_stations(state = "RS", refresh = TRUE, cache_dir = tempdir())
A dataset containing one year of hourly meteorological observations from the automatic station A801 (Porto Alegre, RS), downloaded from INMET.
rmet_examplermet_example
A data frame with columns as returned by inmet_read().
See ?inmet_read for the full variable reference.
INMET – Instituto Nacional de Meteorologia