Skip to contents

Creates a retrieval plan without reading source records. Use [dplyr::collect()] to execute complete batches. Filter and select a lazy source before planning; this plan is not a general dbplyr table. A local data frame is also supported, using the same interval rules with a data.table matcher.

Usage

thip_window(
  data,
  cohort,
  date,
  index = NULL,
  window = NULL,
  by = "pid",
  entry = "entry_id",
  start = NULL,
  end = NULL,
  bounds = "[)"
)

Arguments

data

A lazy ClickHouseHTTP table or local data frame.

cohort

Local data frame with one row per unique entry.

date

Name of the record-date column in data.

index

Reference-date column in cohort, default "index_date" when window is supplied.

window

Two integer day offsets from index, in increasing order.

by

One shared person column, or a named mapping c(source = "cohort").

entry

Unique entry-key column in cohort; must not collide with source columns.

start, end

Explicit cohort date columns, instead of index/window.

bounds

Endpoint inclusion: "[)" (default), "[]", "(]", or "()".

Value

A thip_window_plan, executed with collect().

Details

Relative windows use integer days, not calendar months or years. Dates must be Date values; strings and timestamps are not silently converted. Missing source dates/IDs do not match. Missing cohort keys/dates are rejected. Output contains source columns unchanged plus the cohort entry key. A source row can match multiple entries, and source duplicates are preserved. Entries without matches remain in the input roster; see the attached `window_report` for completion and zero-match counts. An empty clinical row is never invented.

Examples

visits <- data.frame(pid = c("a", "a"),
                     visit_date = as.Date(c("2023-01-01", "2023-01-10")))
entries <- data.frame(pid = "a", entry_id = "e1", index_date = as.Date("2023-01-10"))
plan <- thip_window(visits, entries, date = "visit_date", window = c(-9, 0))
dplyr::collect(plan)
#>   pid visit_date entry_id
#> 1   a 2023-01-01       e1