From c73a3ddfbb03421551c86b40d009cf2754ae8fb2 Mon Sep 17 00:00:00 2001 From: Sebastian Gibb Date: Mon, 10 Jun 2024 11:04:17 +0200 Subject: [PATCH] fix: handle errorneous measurements --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/read_logbook.R | 6 +++++- tests/testthat/test_read_logbook.R | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 07089b3..c1fa2ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dltr Title: Draeger logbook and trend reader -Version: 0.0.2.9000 +Version: 0.0.3 Authors@R: person( given = "Sebastian", family = "Gibb", diff --git a/NEWS.md b/NEWS.md index c9908de..363cead 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ ## Changes in development version +## Changes in 0.0.3 + +- Fix `.melt_measurements` for erroneous values ("ERR" or "+++"). + ## Changes in 0.0.2 - Export `add_anesthesia_case_id`. diff --git a/R/read_logbook.R b/R/read_logbook.R index a89cdaf..ada32f8 100644 --- a/R/read_logbook.R +++ b/R/read_logbook.R @@ -303,7 +303,11 @@ add_anaesthesia_case_id <- function(x) { measure.vars <- colnames(x)[ grepl("^etCO2|^MV|^Pmean|^PIP|^PP|^PEEP|^FiO|^prim.", colnames(x)) ] - x[, (measure.vars) := lapply(.SD, as.double), .SDcols = measure.vars] + x[, + (measure.vars) := + lapply(.SD, function(x)as.double(sub("ERR|\\+\\+\\+", "", x))), + .SDcols = measure.vars + ] m <- melt( x[Label == "Measurements", c("DateTime", measure.vars), with = FALSE], id.vars = "DateTime", diff --git a/tests/testthat/test_read_logbook.R b/tests/testthat/test_read_logbook.R index 95e7b8e..b232f7c 100644 --- a/tests/testthat/test_read_logbook.R +++ b/tests/testthat/test_read_logbook.R @@ -176,8 +176,8 @@ test_that(".melt_measurements", { c(rep("2024-06-04 12:45", 3), "2024-06-04 13:00") ), Label = c("Measurements", "foo", "bar", "Measurements"), - `etCO2 [mmHg]` = c(35, NA, NA, 37), - `MV [l/min]` = c(5.0, NA, NA, 4.8) + `etCO2 [mmHg]` = c(35, "ERR", NA, 37), + `MV [l/min]` = c(5.0, NA, "+++", 4.8) ) r <- data.table( DateTime = lubridate::ymd_hm(