Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions R/supp.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,22 @@ combine_supp_join <- function(dataset, supp) {

# Add message for when there are rows in the supp that didn't get merged
if (nrow(missing) > 0) {
missing_txt <-
capture.output(
missing %>%
select(USUBJID, all_of(current_idvar)) %>%
print()
) %>%
paste0(collapse = "\n")
stop(
paste0(
"Not all rows of the Supp were merged. The following rows are missing:\n",
missing_txt
),
call. = FALSE
)
missing_display <- missing %>%
dplyr::transmute(
USUBJID,
!!current_idvar := IDVARVAL
)
msg <- "Not all rows of SUPP were merged."
cli::cli_alert_warning(msg)

cli::cli_text("")
cli::cli_text("The following rows are missing:")
cli::cli_rule()

print(missing_display)

cli::cli_rule()
warning(msg, call. = FALSE)
}

# join the data
Expand Down
8 changes: 4 additions & 4 deletions man/add_labels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/add_variables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/combine_supp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 17 additions & 15 deletions man/create_var_from_codelist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/set_variable_labels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 106 additions & 3 deletions tests/testthat/test-supp.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,18 @@ test_that("combine_supp works with without QEVAL", {
expect_silent(combine_supp(pharmaversesdtm::tr_onco, pharmaversesdtm::supptr_onco))
})

test_that("supp data that does not match the main data will raise a warning", {
test_that("supp data that does not match the main data will raise a warning but return a dataset", {
sdtm_suppae_extra <- safetyData::sdtm_suppae
sdtm_suppae_extra$IDVARVAL[1] <- 99
expect_error(
combine_supp(safetyData::sdtm_ae, sdtm_suppae_extra)

expect_warning(
out <- combine_supp(safetyData::sdtm_ae, sdtm_suppae_extra),
"Not all rows of SUPP were merged"
)
expect_s3_class(out, "data.frame")
})


test_that("Floating point correction works", {
fp1 <- 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
sdtm_ae_fp <- safetyData::sdtm_ae %>%
Expand Down Expand Up @@ -296,6 +300,105 @@ test_that("combine_supp() does not create an IDVARVAL column (#78)", {
expect_false("IDVARVAL" %in% names(noidvarval))
})

test_that("combine_supp: all SUPP rows merge cleanly (#98)", {
pc <- tibble::tibble(
STUDYID = "STUDY123",
DOMAIN = "PC",
USUBJID = c("01-001", "01-002", "01-003"),
PCSEQ = c(1, 2, 3),
PCTESTCD = "CONC",
PCTEST = "Concentration",
PCORRES = c("5.1", "7.3", "4.8"),
PCORRESU = "ng/mL",
PCSTRESC = c("5.1", "7.3", "4.8"),
PCSTRESN = c(5.1, 7.3, 4.8),
PCSTRESU = "ng/mL",
PCPOS = "PLASMA",
PCDTC = c("2025-07-15T08:00", "2025-07-15T09:00", "2025-07-15T10:00"),
VISITNUM = 1,
VISIT = "Visit 1",
ARM = "Drug A",
ACTARM = "Drug A"
)

supppc <- tibble::tibble(
STUDYID = "STUDY123",
RDOMAIN = "PC",
USUBJID = c("01-001", "01-002", "01-003"),
IDVAR = "PCSEQ",
IDVARVAL = c(1, 2, 3),
QNAM = "PCREASND",
QLABEL = "Reason Not Done",
QVAL = c("NA", "NA", "NA"),
QORIG = "SPONSOR",
QEVAL = "INVESTIGATOR"
)
expect_no_warning(
out <- combine_supp(pc, supppc)
)

expect_s3_class(out, "data.frame")
expect_equal(nrow(out), nrow(pc))
expect_true("PCREASND" %in% names(out))
expect_equal(
unname(as.character(out$PCREASND)),
c("NA", "NA", "NA")
)
})

test_that("combine_supp: extra SUPP rows that do not match core raise a warning but return a dataset(#98)", {
pc <- tibble::tibble(
STUDYID = "STUDY123",
DOMAIN = "PC",
USUBJID = c("01-001", "01-002", "01-003"),
PCSEQ = c(1, 2, 3),
PCTESTCD = "CONC",
PCTEST = "Concentration",
PCORRES = c("5.1", "7.3", "4.8"),
PCORRESU = "ng/mL",
PCSTRESC = c("5.1", "7.3", "4.8"),
PCSTRESN = c(5.1, 7.3, 4.8),
PCSTRESU = "ng/mL",
PCPOS = "PLASMA",
PCDTC = c("2025-07-15T08:00", "2025-07-15T09:00", "2025-07-15T10:00"),
VISITNUM = 1,
VISIT = "Visit 1",
ARM = "Drug A",
ACTARM = "Drug A"
)

supppc <- tibble::tibble(
STUDYID = "STUDY123",
RDOMAIN = "PC",
USUBJID = c("01-001", "01-002", "01-003"),
IDVAR = "PCSEQ",
IDVARVAL = c(1, 2, 3),
QNAM = "PCREASND",
QLABEL = "Reason Not Done",
QVAL = c("NA", "NA", "NA"),
QORIG = "SPONSOR",
QEVAL = "INVESTIGATOR"
)
supppc_extra <- dplyr::bind_rows(
supppc,
dplyr::mutate(supppc[3, ], IDVARVAL = 99),
dplyr::mutate(supppc[3, ], IDVARVAL = 101)
)

expect_warning(
out <- combine_supp(pc, supppc_extra),
"Not all rows of SUPP were merged"
)
expect_s3_class(out, "data.frame")
expect_equal(nrow(out), nrow(pc))
expect_true("PCREASND" %in% names(out))
expect_equal(
unname(as.character(out$PCREASND)),
c("NA", "NA", "NA")
)
expect_false(any(out$PCSEQ %in% c(99, 101)))
})

test_that("build_qnam verbose parameter", {
# Create simple test data with a column that will be used as QNAM
ae <- safetyData::sdtm_ae %>%
Expand Down