Skip to contents

Raw tube identifiers remain opaque. With match_on = "sample" values are matched to the recorded tube (falling back to the scheduled tube); with match_on = "position" they are matched to registration-aware positions.

Usage

merge_saliva(
  study_results,
  saliva,
  correct_swaps = TRUE,
  match_on = c("sample", "position", "physical_id"),
  missing_carwatch_data = c("ignore", "raise"),
  metadata_cols = NULL
)

Arguments

study_results

Complete canonical results.

saliva

Long laboratory tibble.

correct_swaps

Match physical tubes to their recorded position.

match_on

"sample"/"physical_id" or "position".

missing_carwatch_data

Whether unmatched laboratory rows are ignored or rejected.

metadata_cols

Optional laboratory columns to retain as metadata rather than numeric measurements. When omitted, non-numeric non-key columns are treated as metadata. This is the R equivalent of additional pandas index levels. Constant participant-day values are stored at the canonical day level; values varying within any day stay sample-level everywhere.

Value

Complete canonical results with laboratory and merge-provenance fields.

Examples

fixture <- system.file("extdata", "parity", "v1.0.0", package = "carwatch")
results <- read_study_results(file.path(fixture, "results.csv"))
saliva <- read_saliva(file.path(fixture, "saliva.csv"))
merged <- merge_saliva(results, saliva)
as_sample_events(merged)[c("participant", "sample", "cortisol")]
#> # A tibble: 2 × 3
#>   participant sample cortisol
#>   <chr>       <chr>     <dbl>
#> 1 VP01        tube-a        5
#> 2 VP01        tube-b        9