R Under development (unstable) (2026-02-18 r89435 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(medicalcoder) > > # Verifies cumulative flagging behavior for Charlson when poa/poa.var is omitted. > # Expected default: first encounter for a condition is NOT flagged (poa defaults > # to 0), but the condition carries forward and is flagged on later encounters > # (poa set to 1 after first occurrence). Explicit poa = 1 should flag all > # encounters. > > df <- data.frame( + patid = c(1L, 1L), + enc = c(1L, 2L), + icdv = c(10L, 10L), + dx = c(1L, 1L), + code = c("I252", "I252"), + stringsAsFactors = FALSE + ) > > # Baseline: explicit poa = 1 flags the condition under cumulative logic > explicit_poa <- comorbidities( + data = df, + icd.codes = "code", + id.vars = c("patid", "enc"), + icdv.var = "icdv", + dx.var = "dx", + method = "charlson_quan2011", + flag.method = "cumulative", + poa = 1L, + primarydx = 0L + ) > > stopifnot(any(explicit_poa[["cmrb_flag"]])) > stopifnot( + explicit_poa$cmrb_flag[explicit_poa$enc == 1L] == 1L, + explicit_poa$cmrb_flag[explicit_poa$enc == 2L] == 1L + ) > > # Without specifying poa/poa.var, encounter 1 should remain unflagged and > # encounter 2 should be flagged. > default_poa <- comorbidities( + data = df, + icd.codes = "code", + id.vars = c("patid", "enc"), + icdv.var = "icdv", + dx.var = "dx", + method = "charlson_quan2011", + flag.method = "cumulative", + primarydx = 0L + ) Warning message: 'poa.var' and 'poa' are both NULL. With flag.method = 'cumulative' poa is set to 0. > > stopifnot( + default_poa$cmrb_flag[default_poa$enc == 1L] == 0L, + default_poa$cmrb_flag[default_poa$enc == 2L] == 1L + ) > > proc.time() user system elapsed 4.76 0.40 5.14