GEMINI-Medicine / Rgemini

A custom R package that provides a variety of functions to perform data analyses with GEMINI data
https://gemini-medicine.github.io/Rgemini/
Other
3 stars 0 forks source link

Fix frailty_score to return encounters with score of 0 #130

Closed gemini-wenb closed 4 months ago

gemini-wenb commented 4 months ago

The function calculates frailty score as expected and assigns 0 to encounters without any frailty conditions. At the step of returning results, it calls the object without the rows with zero scores. This PR fixed the bug by calling the correct object to return.

gemini-wenb commented 4 months ago

Good catch, thanks Bijun for implementing the fix! I tested it and it works as expected now. Just 2 small things:

  1. Could you add a note about the bug fix in NEWS.md?
  2. We could potentially add a unit test like this (feel free to edit)?
testthat::test_that("Encounters with no frailty condition are returned with frailty = 0", {
  set.seed(2)
  cohort_dum <- data.table(genc_id=c(1), age=c(89))
  ipdiag_dum <- dummy_diag(nid=1, nrow=10, ipdiagnosis=T, pattern ="A05$") # no frailty condition

  testthat::expect_warning(res <- frailty_score(cohort_dum, ipdiag_dum, NULL))
  testthat::expect_equal(res$frailty_score_derived, c(0))
})

Thanks for reviewing @loffleraSMH and great suggestions! I've added the unit test and updated NEWS.md.

loffleraSMH commented 4 months ago

Thanks @gemini-wenb! Everything looks good now. Feel free to go ahead and merge this.