Skip to content

Commit

Permalink
804 ttet01 fails with empty level in arm_var (#805)
Browse files Browse the repository at this point in the history
close #804 

refine the assertion in the ttet01 template and add test

thank you for the review
  • Loading branch information
BFalquet authored Jan 9, 2025
1 parent ece0972 commit 3f43376
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion R/ttet01.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-ttet01.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3f43376

Please sign in to comment.