Skip to contents

Reads one or more variables from a NetCDF file and returns a named list of data.frames (one per variable). Each data.frame contains the coordinate columns (e.g., lon/lat/time) plus a single value column (optionally renamed).

Usage

read_netcdf(
  nc_path,
  var = NULL,
  var_name = NULL,
  keep_leap_day = TRUE,
  drop_all_na = TRUE,
  spatial_ref = "spatial_ref",
  signif_digits = NULL,
  verbose = FALSE
)

Arguments

nc_path

Character. Path to NetCDF file.

var

Character vector or NULL. Variables to read. If NULL, reads all non-coordinate variables (and excludes `spatial_ref` if present).

var_name

NULL, or named character vector. - If named: names are original variable names and values are new names. Renaming applies to output list names and the value-column name.

keep_leap_day

Logical. If FALSE and time is convertible to Date, removes Feb 29 rows.

drop_all_na

Logical. If TRUE, drop variables whose values are all NA after applying _FillValue/missing_value handling.

spatial_ref

Character. Name of a spatial reference variable to ignore when auto-selecting variables (common in CF/CRS-encoded files).

signif_digits

Integer or NULL. If provided, rounds numeric values via signif(x, signif_digits).

verbose

Logical. If TRUE, prints basic progress messages.

Value

Named list of data.frames.

Details

Robust to common NetCDF conventions and avoids the "replacement has N rows, data has 0" failure by always building the coordinate table at the correct length before assigning values.