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. > ################################################################################ > # Verify primary diagnoses are excluded from comorbidity flagging > library(medicalcoder) > > df <- data.frame( + patid = c(1L, 2L), + icdv = c(10L, 10L), + dx = c(1L, 1L), + code = c("I252", "I252"), # MI code that should flag Charlson when counted + primarydx = c(0L, 1L), + stringsAsFactors = FALSE + ) > > res0 <- comorbidities( + data = df, + id.vars = "patid", + icdv.var = "icdv", + dx.var = "dx", + icd.codes = "code", + method = "charlson_quan2011", + poa = 1L, + primarydx = 0L + ) > > res1 <- comorbidities( + data = df, + id.vars = "patid", + icdv.var = "icdv", + dx.var = "dx", + icd.codes = "code", + method = "charlson_quan2011", + poa = 1L, + primarydx = 1L + ) > > resv <- comorbidities( + data = df, + id.vars = "patid", + icdv.var = "icdv", + dx.var = "dx", + icd.codes = "code", + method = "charlson_quan2011", + poa = 1L, + primarydx.var = "primarydx" + ) > > stopifnot(identical(res0[["cmrb_flag"]], c(1L, 1L))) > stopifnot(identical(res1[["cmrb_flag"]], c(0L, 0L))) > stopifnot(identical(resv[["cmrb_flag"]], c(1L, 0L))) > > ################################################################################ > # End of File # > ################################################################################ > > proc.time() user system elapsed 3.32 0.48 3.79