Skip to content

Commit

Permalink
Merge pull request #63 from InsightRX/tidier_scr_conversion
Browse files Browse the repository at this point in the history
tidier scr unit conversion
  • Loading branch information
jasmineirx authored Sep 30, 2024
2 parents a092898 + e616c48 commit 711ccd2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/calc_egfr.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ calc_egfr <- function (
scr_unit <- rep(scr_unit, length(scr))
}
scr_unit <- tolower(gsub("%2F", "/", scr_unit))
scr[scr_unit != "mg/dl"] <- scr[scr_unit != "mg/dl"] / 88.4
scr <- convert_creat_unit(scr, scr_unit, "mg/dl")$value

# ---- Format Sex
sex <- ifelse(is.nil(sex), '', tolower(sex))
Expand Down
33 changes: 33 additions & 0 deletions tests/testthat/test_calc_egfr.R
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,36 @@ test_that("calc_egfr warns and returns NULL if sex isn't supported", {
)
expect_null(res$value)
})

test_that("calc_egfr converts scr appropriately", {
res1 <- calc_egfr(
age = 40,
sex = "female",
weight = 80,
scr = 1,
scr_unit = "MG/DL",
method = "cockcroft_gault",
verbose = FALSE
)
res2 <- calc_egfr(
age = 40,
sex = "female",
weight = 80,
scr = 1,
scr_unit = "mg_dl",
method = "cockcroft_gault",
verbose = FALSE
)
res3 <- calc_egfr(
age = 40,
sex = "female",
weight = 80,
scr = 1 * 10e3/113.12,
scr_unit = "micromol_l",
method = "cockcroft_gault",
verbose = FALSE
)
expect_equal(res1$value, 94.444444)
expect_equal(res2$value, 94.444444)
expect_equal(res3$value, 94.444444)
})

0 comments on commit 711ccd2

Please sign in to comment.