Skip to contents

Reads an INMET dataset previously created with [build_inmet_dataset()]. The dataset is accessed through the Arrow Dataset interface, allowing efficient filtering without loading all observations into memory.

Usage

read_inmet(
  path = NULL,
  years = NULL,
  stations = NULL,
  variables = NULL,
  collect = FALSE
)

Arguments

path

Character. Path to the directory containing the processed INMET dataset.

years

Integer vector of years to read. If `NULL`, all available years are returned.

stations

Character vector of WMO station codes. If `NULL`, all stations are returned.

variables

Character vector of variables (columns) to return. If `NULL`, all variables are returned.

collect

Logical. If `TRUE`, the filtered dataset is collected into memory as a data frame. If `FALSE` (default), an Arrow Dataset query is returned.

Value

If `collect = FALSE`, returns an Arrow Dataset query. If `collect = TRUE`, returns a data frame containing the selected observations.

Details

The function performs filtering directly on disk whenever possible, making it suitable for working with large datasets.

Setting `collect = TRUE` loads the selected observations into memory. This may require a large amount of RAM when reading many years or stations simultaneously. Consider filtering by year, station, or variables before collecting the data.

See also

[download_inmet()], [build_inmet_dataset()]

Examples

# Requires INMET data downloaded with download_inmet() and
# processed into an Arrow dataset with build_inmet_dataset().
# See the vignette "climateBR: An R package to download meteorological data from Brazil".
# for the complete workflow of this function.

if (FALSE) { # \dontrun{

## Read a single year without loading the data into memory
rainfall_df1 <- read_inmet(
  path = dataset_dir,
  years = 2000,
  collect = FALSE
)

## Read multiple years and collect the results into memory
rainfall_df2 <- read_inmet(
  path = dataset_dir,
  years = 2000:2005,
  collect = TRUE
)

## For large datasets, keeping collect = FALSE is generally
## recommended to avoid excessive memory usage.
} # }