From f17a4daad56ed043032bdd4f58c2daf0f68eee03 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Tue, 9 Sep 2025 19:01:54 +0000 Subject: [PATCH 1/2] fix behavior + test --- DESCRIPTION | 4 ++-- R/parse_input_data.R | 1 + tests/testthat/test-parse_input_data.R | 27 +++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7e07728..50b6b75 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: PKPDmap Type: Package Title: MAP Bayesian estimates -Version: 1.1.4 -Date: 2025-07-12 +Version: 1.1.5 +Date: 2025-09-09 Author: Ron Keizer, Jasmine Hughes, Kara Woo Maintainer: Ron Keizer Description: Obtain MAP Bayesian estimates based on individual data and diff --git a/R/parse_input_data.R b/R/parse_input_data.R index aefe23b..84bffb5 100644 --- a/R/parse_input_data.R +++ b/R/parse_input_data.R @@ -13,6 +13,7 @@ parse_input_data <- function( } else { data$obs_type <- data[[obs_type_label]] } + data$OBS_TYPE <- NULL # ensure there is no duplicate `obs_type` column colnames(data) <- tolower(colnames(data)) if(!all(tolower(unlist(cols)) %in% names(data))) { stop("Expected column names were not found in data. Please use 'cols' argument to specify column names for independent and dependent variable.") diff --git a/tests/testthat/test-parse_input_data.R b/tests/testthat/test-parse_input_data.R index 05b279e..051992e 100644 --- a/tests/testthat/test-parse_input_data.R +++ b/tests/testthat/test-parse_input_data.R @@ -1,4 +1,4 @@ -test_that("parse_input_data handles regular data frame input", { +test_that("parse_input_data handles regular data frame input, with OBS_TYPE label but not specified as `obs_type_label`", { # Create test data data <- data.frame( T = c(2, 1, 3), @@ -6,16 +6,37 @@ test_that("parse_input_data handles regular data frame input", { Y = c(10, 20, 30) ) - result <- parse_input_data(data) + result <- parse_input_data(data, obs_type_label = NULL) # Check column names are lowercase - expect_equal(names(result), c("t", "obs_type", "y", "obs_type")) + expect_equal(names(result), c("t", "y", "obs_type")) + + # Check sorting + expect_equal(result$t, c(1, 2, 3)) + expect_equal(result$obs_type, c(1, 1, 1)) + +}) + +test_that("parse_input_data handles regular data frame input, with OBS_TYPE label, properly specified as `obs_type_label`", { + # Create test data + data <- data.frame( + T = c(2, 1, 3), + OBS_TYPE = c(2, 1, 1), + Y = c(10, 20, 30) + ) + + result <- parse_input_data(data, obs_type_label = "OBS_TYPE") + + # Check column names are lowercase + expect_equal(names(result), c("t", "y", "obs_type")) # Check sorting expect_equal(result$t, c(1, 2, 3)) expect_equal(result$obs_type, c(1, 2, 1)) + }) + test_that("parse_input_data handles PKPDsim object", { # Create mock PKPDsim object data <- structure( From 3ffc0f79b7fbdcd43d6ab42a19c9c5cdf5ec8882 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Wed, 10 Sep 2025 15:45:18 +0000 Subject: [PATCH 2/2] add test for edge case --- DESCRIPTION | 4 ++-- tests/testthat/test-parse_input_data.R | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 50b6b75..11b74e6 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: PKPDmap Type: Package Title: MAP Bayesian estimates -Version: 1.1.5 -Date: 2025-09-09 +Version: 1.1.6 +Date: 2025-09-10 Author: Ron Keizer, Jasmine Hughes, Kara Woo Maintainer: Ron Keizer Description: Obtain MAP Bayesian estimates based on individual data and diff --git a/tests/testthat/test-parse_input_data.R b/tests/testthat/test-parse_input_data.R index 051992e..53df283 100644 --- a/tests/testthat/test-parse_input_data.R +++ b/tests/testthat/test-parse_input_data.R @@ -17,6 +17,18 @@ test_that("parse_input_data handles regular data frame input, with OBS_TYPE labe }) +test_that("parse_input_data picks right column, even with lower/uppercase duplicates", { + data <- data.frame( + T = c(1, 2, 3), + obs_type = c(1, 0, 1), + OBS_TYPE = c(2, 1, 1), + Y = c(10, 20, 30) + ) + result <- parse_input_data(data, obs_type_label = "OBS_TYPE") + expect_equal(result$obs_type, c(2, 1, 1)) + expect_equal(sum(tolower(names(result)) == "obs_type"), 1) +}) + test_that("parse_input_data handles regular data frame input, with OBS_TYPE label, properly specified as `obs_type_label`", { # Create test data data <- data.frame(