diff --git a/NEWS.md b/NEWS.md index 3330cf8cb..2c60c7193 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # chevron 0.2.8.9006 +* `ttet01_main` now prints a clearer error message when a level in `arm_var` variable is missing. + # chevron 0.2.8 * New `unwrap` argument prints `preprocessing`, `main`, `postprocessing` and `layout` function upon execution of the `run` method. diff --git a/R/ttet01.R b/R/ttet01.R index 6f14caf18..5594f8a68 100644 --- a/R/ttet01.R +++ b/R/ttet01.R @@ -46,9 +46,10 @@ ttet01_main <- function(adam_db, assert_valid_variable(adam_db[[dataset]], c("IS_EVENT", "IS_NOT_EVENT"), types = list("logical"), label = df_label) assert_valid_variable(adam_db[[dataset]], "AVAL", types = list("numeric"), lower = 0, label = df_label) assert_valid_variable( - adam_db[[dataset]], c("USUBJID", strata, arm_var, "EVNT1", "EVNTDESC", "AVALU"), + adam_db[[dataset]], c("USUBJID", strata, "EVNT1", "EVNTDESC", "AVALU"), types = list(c("character", "factor")), label = df_label ) + assert_valid_variable(adam_db[[dataset]], arm_var, types = list("factor"), empty.levels.ok = FALSE, label = df_label) assert_subset(ref_group, lvls(adam_db[[dataset]][[arm_var]])) ref_group <- ref_group %||% lvls(anl[[arm_var]])[1] assert_single_value(anl$AVALU, label = sprintf("adam_db$%s$AVALU", dataset)) diff --git a/tests/testthat/test-ttet01.R b/tests/testthat/test-ttet01.R index 609ad9e02..6c617983d 100644 --- a/tests/testthat/test-ttet01.R +++ b/tests/testthat/test-ttet01.R @@ -10,6 +10,18 @@ test_that("ttet01 works as expected", { expect_snapshot(cat(export_as_txt(res, lpp = 100))) }) +test_that("ttet01 returns an error when one level or arm_var is empty", { + proc_data <- syn_data %>% + dunlin::log_filter(PARAMCD == "PFS", "adtte") %>% + dunlin::log_filter(ARM != "C: Combination", "adtte") + + expect_error( + run(ttet01, proc_data, dataset = "adtte"), + "* Variable 'adam_db$adtte$ARM': Has has empty levels 'C: Combination'.", + fixed = TRUE + ) +}) + test_that("ttet01 works as expected for stratified and unstratified analysis", { skip_on_os("windows") filter_data <- dunlin::log_filter(syn_data, PARAMCD == "PFS", "adtte")