Skip to content

Commit fba37dd

Browse files
authored
Merge pull request #55 from InsightRX/RXR-2722
fix behavior + test
2 parents 9490885 + 3ffc0f7 commit fba37dd

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: PKPDmap
22
Type: Package
33
Title: MAP Bayesian estimates
4-
Version: 1.1.4
5-
Date: 2025-07-12
4+
Version: 1.1.6
5+
Date: 2025-09-10
66
Author: Ron Keizer, Jasmine Hughes, Kara Woo
77
Maintainer: Ron Keizer <ron@insight-rx.com>
88
Description: Obtain MAP Bayesian estimates based on individual data and

R/parse_input_data.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ parse_input_data <- function(
1313
} else {
1414
data$obs_type <- data[[obs_type_label]]
1515
}
16+
data$OBS_TYPE <- NULL # ensure there is no duplicate `obs_type` column
1617
colnames(data) <- tolower(colnames(data))
1718
if(!all(tolower(unlist(cols)) %in% names(data))) {
1819
stop("Expected column names were not found in data. Please use 'cols' argument to specify column names for independent and dependent variable.")

tests/testthat/test-parse_input_data.R

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,54 @@
1-
test_that("parse_input_data handles regular data frame input", {
1+
test_that("parse_input_data handles regular data frame input, with OBS_TYPE label but not specified as `obs_type_label`", {
22
# Create test data
33
data <- data.frame(
44
T = c(2, 1, 3),
55
OBS_TYPE = c(2, 1, 1),
66
Y = c(10, 20, 30)
77
)
88

9-
result <- parse_input_data(data)
9+
result <- parse_input_data(data, obs_type_label = NULL)
1010

1111
# Check column names are lowercase
12-
expect_equal(names(result), c("t", "obs_type", "y", "obs_type"))
12+
expect_equal(names(result), c("t", "y", "obs_type"))
13+
14+
# Check sorting
15+
expect_equal(result$t, c(1, 2, 3))
16+
expect_equal(result$obs_type, c(1, 1, 1))
17+
18+
})
19+
20+
test_that("parse_input_data picks right column, even with lower/uppercase duplicates", {
21+
data <- data.frame(
22+
T = c(1, 2, 3),
23+
obs_type = c(1, 0, 1),
24+
OBS_TYPE = c(2, 1, 1),
25+
Y = c(10, 20, 30)
26+
)
27+
result <- parse_input_data(data, obs_type_label = "OBS_TYPE")
28+
expect_equal(result$obs_type, c(2, 1, 1))
29+
expect_equal(sum(tolower(names(result)) == "obs_type"), 1)
30+
})
31+
32+
test_that("parse_input_data handles regular data frame input, with OBS_TYPE label, properly specified as `obs_type_label`", {
33+
# Create test data
34+
data <- data.frame(
35+
T = c(2, 1, 3),
36+
OBS_TYPE = c(2, 1, 1),
37+
Y = c(10, 20, 30)
38+
)
39+
40+
result <- parse_input_data(data, obs_type_label = "OBS_TYPE")
41+
42+
# Check column names are lowercase
43+
expect_equal(names(result), c("t", "y", "obs_type"))
1344

1445
# Check sorting
1546
expect_equal(result$t, c(1, 2, 3))
1647
expect_equal(result$obs_type, c(1, 2, 1))
48+
1749
})
1850

51+
1952
test_that("parse_input_data handles PKPDsim object", {
2053
# Create mock PKPDsim object
2154
data <- structure(

0 commit comments

Comments
 (0)