From 798e4d6ce4a8b639e2ce4635f10d09dde4455806 Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Tue, 3 Jun 2025 19:04:29 -0400 Subject: [PATCH 1/3] adds a few more unit conversion options --- R/convert_conc_unit.R | 8 +++++++- tests/testthat/test_convert_conc_unit.R | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/R/convert_conc_unit.R b/R/convert_conc_unit.R index 4208dd8..4052204 100644 --- a/R/convert_conc_unit.R +++ b/R/convert_conc_unit.R @@ -31,6 +31,10 @@ 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, @@ -38,7 +42,9 @@ convert_conc_unit <- function(value, unit_in, unit_out, mol_weight = NULL) { `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..cbc9386 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,7 @@ 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) }) test_that("vectorized input works", { From 2ab102debd3e8051c9027408d724928843c3275a Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Tue, 3 Jun 2025 19:32:21 -0400 Subject: [PATCH 2/3] also add mmol_l --- R/convert_conc_unit.R | 4 +++- tests/testthat/test_convert_conc_unit.R | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/convert_conc_unit.R b/R/convert_conc_unit.R index 4052204..3c4c89d 100644 --- a/R/convert_conc_unit.R +++ b/R/convert_conc_unit.R @@ -38,7 +38,9 @@ convert_conc_unit <- function(value, unit_in, unit_out, mol_weight = NULL) { `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, diff --git a/tests/testthat/test_convert_conc_unit.R b/tests/testthat/test_convert_conc_unit.R index cbc9386..fb8beac 100644 --- a/tests/testthat/test_convert_conc_unit.R +++ b/tests/testthat/test_convert_conc_unit.R @@ -20,6 +20,7 @@ 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", { From 0dcfc427f73832d521a15695e32b4bb102ddcde6 Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Wed, 4 Jun 2025 14:53:05 -0400 Subject: [PATCH 3/3] fix forgotten slash --- R/convert_conc_unit.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/convert_conc_unit.R b/R/convert_conc_unit.R index 3c4c89d..8786252 100644 --- a/R/convert_conc_unit.R +++ b/R/convert_conc_unit.R @@ -40,7 +40,7 @@ convert_conc_unit <- function(value, unit_in, unit_out, mol_weight = NULL) { micromol = mol_weight, mmol = mol_weight * 1000, mmol_l = 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,