diff --git a/R/convert_conc_unit.R b/R/convert_conc_unit.R index 4208dd8..8786252 100644 --- a/R/convert_conc_unit.R +++ b/R/convert_conc_unit.R @@ -31,14 +31,22 @@ convert_conc_unit <- function(value, unit_in, unit_out, mol_weight = NULL) { `g/l` = 1000000, mg_dl = 10000, `mg/dl` = 10000, + mg_l = 1000, + `mg/l` = 1000, + pg_ml = 1e-3, + `pg/ml` = 1e-3, `micromol/l` = mol_weight, micromol_l = mol_weight, micromol = mol_weight, - mmol = mol_weight, + mmol = mol_weight * 1000, + mmol_l = mol_weight * 1000, + `mmol/l` = mol_weight * 1000, `mumol/l` = mol_weight, `umol/l` = mol_weight, mumol_l = mol_weight, - umol_l = mol_weight + umol_l = mol_weight, + pmol_l = mol_weight * 1e-6, + `pmol/l` = mol_weight * 1e-6 ) unit_out <- match.arg(unit_out, names(conv)) diff --git a/tests/testthat/test_convert_conc_unit.R b/tests/testthat/test_convert_conc_unit.R index 6424782..fb8beac 100644 --- a/tests/testthat/test_convert_conc_unit.R +++ b/tests/testthat/test_convert_conc_unit.R @@ -5,6 +5,8 @@ test_that("convert_conc_unit can convert g/dl, g/l, mg/dl", { expect_equal(convert_conc_unit(1, "mg_dl", "g_dl")$value, .001) expect_equal(convert_conc_unit(1, "mg_dl", "g_l")$value, 0.01) expect_equal(convert_conc_unit(1, "g_l", "mg_dl")$value, 100) + expect_equal(convert_conc_unit(1, "g_l", "mg_l")$value, 1000) + expect_equal(convert_conc_unit(1, "mg_l", "pg_ml")$value, 1e6) }) test_that("molecular weight required when converting molar units", { @@ -17,6 +19,8 @@ test_that("molecular weight required when converting molar units", { test_that("molar unit conversion works", { expect_equal(convert_conc_unit(1, "mg_dl", "micromol_l", 0.5)$value, 20000) + expect_equal(convert_conc_unit(200, "pg_ml", "pmol_l", 50)$value, 4000) + expect_equal(convert_conc_unit(1, "mmol_l", "pmol_l", 17)$value, 1e9) }) test_that("vectorized input works", {