| Type: | Package |
| Title: | Download and Read Brazilian Meteorological Data from INMET |
| Version: | 0.1.0 |
| Description: | Automates the download and processing of historical weather data from the Brazilian National Institute of Meteorology (INMET). It resolves formatting inconsistencies in raw CSV files across different years, removes structural artifacts, standardizes column names, converts timestamps to local Brazilian time zones, and outputs tidy data frames ready for analysis. Data are retrieved from https://portal.inmet.gov.br/dadoshistoricos. |
| Depends: | R (≥ 4.0.0) |
| Encoding: | UTF-8 |
| LazyData: | true |
| Language: | en-US |
| License: | GPL (≥ 3) |
| URL: | https://github.com/rodrigosqrt3/rmet |
| BugReports: | https://github.com/rodrigosqrt3/rmet/issues |
| RoxygenNote: | 7.3.3 |
| Imports: | curl |
| Suggests: | spelling, testthat (≥ 3.0.0), knitr, rmarkdown |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-04-21 19:00:40 UTC; rodri |
| Author: | Rodrigo Fonseca Villa
|
| Maintainer: | Rodrigo Fonseca Villa <rodrigo03.villa@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-21 21:22:09 UTC |
rmet: Access Historical Weather Data from INMET
Description
The rmet package provides tools to download, cache, and parse
historical hourly weather data from Brazil's National Institute of
Meteorology (INMET).
Main functions
-
inmet_download()— Download annual ZIP files with resume support. -
inmet_read()— Parse downloaded ZIPs into a tidydata.frame. -
inmet_extract()— Unzip CSVs to a directory. -
inmet_stations()— Browse the bundled station catalogue.
Data source
Data is retrieved from "portal.inmet.gov.br/dadoshistoricos". Please consult INMET's terms of use before redistributing the raw data.
Author(s)
Maintainer: Rodrigo Fonseca Villa rodrigo03.villa@gmail.com (ORCID)
See Also
Useful links:
Clear the rmet download cache
Description
Deletes downloaded ZIP files from the cache directory.
Usage
inmet_cache_clear(
years = NULL,
dest_dir = tools::R_user_dir("rmet", "cache"),
ask = interactive()
)
Arguments
years |
Integer vector of years to remove, or |
dest_dir |
Character. Cache directory. |
ask |
Logical. If |
Value
Invisible NULL.
Check which years have already been downloaded
Description
Convenience function that scans the cache directory and reports which annual ZIPs are present and valid.
Usage
inmet_cache_status(dest_dir = tools::R_user_dir("rmet", "cache"))
Arguments
dest_dir |
Character. Cache directory (same as |
Value
A data.frame with columns year (integer), path (character),
size_mb (numeric), and valid (logical, whether the ZIP passes
integrity check).
Examples
inmet_cache_status()
Download INMET historical data ZIPs with resume support
Description
Downloads one or more annual ZIP files from INMET's historical data portal. Downloads are resumable: if a partial file is already on disk (e.g., from a previous interrupted session), the function picks up where it left off instead of restarting.
Usage
inmet_download(
years = as.integer(format(Sys.Date(), "%Y")),
dest_dir = tools::R_user_dir("rmet", "cache"),
max_tries = 15L,
quiet = FALSE,
force = FALSE
)
Arguments
years |
Integer vector of years to download. Available years start from 2000. Defaults to the current year. |
dest_dir |
Character. Directory where ZIP files will be saved.
Created automatically if it does not exist. Defaults to a persistent
cache directory under |
max_tries |
Integer. Maximum number of download attempts per year
before giving up. Defaults to |
quiet |
Logical. If |
force |
Logical. If |
Details
INMET's server sometimes drops connections mid-transfer. The function
handles this by using curl's CURLOPT_RESUME_FROM to append to the
partial file on each retry, then validates the result with
utils::unzip(). A Sys.sleep(5) back-off separates retries.
ZIP files are not extracted by this function. Use inmet_read() to
parse the contents directly from the ZIP, or inmet_extract() to unzip
to a directory.
Value
Invisibly returns a named character vector (class character) of
local file paths to the downloaded ZIP files. Names correspond to the
requested years (e.g., "2023"). Years that failed to download are
excluded. If all downloads fail, an empty named character vector is
returned.
See Also
Examples
paths <- inmet_download(years = 2000, dest_dir = tempdir())
Extract and save INMET ZIP contents to a directory
Description
Unzips one or more downloaded INMET annual ZIPs to a target directory, preserving the original CSV files.
Usage
inmet_extract(
years,
dest_dir = tools::R_user_dir("rmet", "cache"),
out_dir = file.path(dest_dir, "csv"),
overwrite = FALSE,
quiet = FALSE
)
Arguments
years |
Integer vector of years to extract. |
dest_dir |
Character. Directory of ZIP files (same as |
out_dir |
Character. Directory where CSVs will be written. Defaults to
a subdirectory |
overwrite |
Logical. Overwrite existing CSVs? Defaults to |
quiet |
Logical. Suppress messages. Defaults to |
Value
Invisible character vector of paths to all extracted CSV files.
Read INMET station data from downloaded ZIP files
Description
Parses the CSV files inside INMET annual ZIP archives and returns a single
tidy data.frame with consistent column names, correct data types, and a
proper POSIXct timestamp column.
Usage
inmet_read(
years,
stations = NULL,
dest_dir = tools::R_user_dir("rmet", "cache"),
tz = "America/Sao_Paulo",
variables = NULL,
start_date = NULL,
end_date = NULL,
quiet = FALSE
)
Arguments
years |
Integer vector of years to read. Each year must have a
corresponding ZIP file in |
stations |
Character vector of station codes (e.g., |
dest_dir |
Character. Directory containing the ZIP files. Defaults to
the same cache directory used by |
tz |
Character. Time zone for the |
variables |
Character vector of variable names to keep. If |
start_date |
Character. Optional start date in |
end_date |
Character. Optional end date in |
quiet |
Logical. Suppress progress messages. Defaults to |
Value
A data.frame containing the parsed INMET data.
Columns include station identifiers (station_code, region,
state, latitude, longitude, elevation),
a POSIXct datetime column, and various meteorological
measurements (temperature, precipitation, pressure, humidity, wind, and radiation).
Returns an empty data.frame if no data is found.
Variables
You can pass a subset of the output column names to variables to limit
what is returned, e.g.:
variables = c("temp_dry_c", "precip_mm", "humid_rel_pct").
See Also
inmet_download(), inmet_stations()
Examples
df <- inmet_read(
years = 2000,
stations = "A801",
dest_dir = tempdir()
)
head(df)
List INMET automatic weather stations
Description
Returns a data.frame of all INMET automatic weather stations (estações
automáticas) with their metadata. The catalogue is bundled with the package
and reflects the stations as of the package release date.
Usage
inmet_stations(region = NULL, state = NULL, search = NULL)
Arguments
region |
Character vector. Filter by macro-region code(s):
|
state |
Character vector. Filter by two-letter state abbreviation(s)
(e.g., |
search |
Character. A free-text search string applied to the station
name column (case-insensitive, partial matching). If |
Value
A data.frame with columns:
station_codeCharacter. INMET four-character station identifier.
station_nameCharacter. Station name.
regionCharacter. Macro-region code.
stateCharacter. Two-letter state abbreviation.
latitudeNumeric. Decimal degrees (negative = south).
longitudeNumeric. Decimal degrees (negative = west).
elevationNumeric. Altitude in metres.
start_yearInteger. Year from which data is available.
See Also
inmet_download(), inmet_read()
Examples
# All stations
st <- inmet_stations()
nrow(st)
# Stations in Rio Grande do Sul
st_rs <- inmet_stations(state = "RS")
# Search by name
inmet_stations(search = "porto alegre")
Hourly weather data from INMET station A801 (Porto Alegre), 2023
Description
A dataset containing one year of hourly meteorological observations from the automatic station A801 (Porto Alegre, RS), downloaded from INMET.
Usage
rmet_example
Format
A data frame with columns as returned by inmet_read().
See ?inmet_read for the full variable reference.
Source
INMET – Instituto Nacional de Meteorologia