Skip to contents

Applies scan_windows() to many site-specific reference dates and returns a wide table with one row per reference event and one column per metric-window combination. The reference date can be an assessment date, planting date, or any other timestamp stored in the input table.

Usage

window_pane(
  weather,
  assessments,
  windows,
  reference_col = NULL,
  id_col = NULL,
  response_col = NULL,
  weather_cols,
  time_col = "time",
  unit = c("days", "hours"),
  statistics,
  site_col = id_col,
  sampling_interval = NULL,
  max_allowed_missing_pct = NULL
)

Arguments

weather

A weather data frame.

assessments

A data frame containing reference times and optional IDs or responses.

windows

A data frame created by make_windows() or define_windows().

reference_col

Name of the reference timestamp column. If NULL, the function uses metadata stored by make_windows() or falls back to "assessment_time".

id_col

Optional identifier column from assessments to retain. By default it also serves as the site key.

response_col

Optional response column, such as disease intensity.

weather_cols

Required character vector of existing numeric weather columns. Column names must be unique, non-missing, and non-empty. If named, every entry must have a unique, non-missing, non-empty output alias; .conditions is reserved. No columns are inferred. Use character() explicitly for condition-only summaries.

time_col

Name of the weather timestamp column.

unit

Time unit for relative-time windows. One of "days" or "hours".

statistics

Required summary specification. Use a non-empty character vector to apply the same statistics to all weather_cols, such as c("mean", "sd", "IQR"). Alternatively, use a named list keyed by every selected column's output alias (or column name when unnamed), with no unknown keys. Each entry must be a non-empty character vector or a nested named list of functions or single function names, for example list(temp = list(avg = "mean", spread = stats::sd)). Statistic names must be unique, non-missing, and non-empty. No summaries are inferred. The optional .conditions entry is a named list of multivariable condition summaries such as count_when(temp >= 18 & rh >= 90).

site_col

Column used to match sites in both tables. Defaults to id_col. Set explicitly to NULL for one shared weather series, even when retaining an assessment identifier with id_col. A site key must contain no missing or blank values and every assessment site must have weather.

sampling_interval

Expected spacing between measurements, in unit. If NULL, uses the shortest gap between recorded timestamps within the series, or one unit if fewer than two timestamps are available. Supply the spacing when gaps may hide the actual sampling frequency.

max_allowed_missing_pct

Optional maximum missing percentage (0 to 100). Drop a predictor column if any assessment exceeds the limit. Its diagnostics remain in coverage. NULL keeps all predictor columns.

Value

A list with two data frames in assessment order. features holds identifiers, the optional response, and predictors. coverage holds identifiers, row counts, and missing percentages. A single message reports missing data when present.

Details

Configured time, ID, site, reference, and response columns cannot be selected in weather_cols. Empty assessment tables are rejected.