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
1 change: 0 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
linters: linters_with_defaults(
line_length_linter = line_length_linter(120),
cyclocomp_linter = NULL,
object_usage_linter = NULL
)
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Depends:
formatters (>= 0.5.10.9001),
R (>= 4.2),
rlistings (>= 0.2.10),
rtables (>= 0.6.11),
tern (>= 0.9.7.9003)
rtables (>= 0.6.11.9017),
tern (>= 0.9.7.9018)
Imports:
pharmaverseadam (>= 1.1.0),
random.cdisc.data (>= 0.3.16)
Expand All @@ -46,6 +46,7 @@ VignetteBuilder:
knitr
Remotes:
insightsengineering/formatters@main,
insightsengineering/rtables@main,
insightsengineering/tern@main,
pharmaverse/pharmaverseadam@main
biocViews:
Expand Down
252 changes: 252 additions & 0 deletions tests/testthat/_snaps/char-support.md

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions tests/testthat/_snaps/table_aovt01.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,47 @@
95% CI (-1.17, 2.76) (-0.56, 3.39)
p-value 0.4288 0.1591

# AOVT01 variant with proportional weights is produced correctly

Code
res
Output
ARM A ARM B ARM C
(N=134) (N=134) (N=132)
——————————————————————————————————————————————————————————————————————————
BFIALL
Adjusted mean
n 134 134 132
Adjusted Mean 4.50 6.36 4.05
Difference in Adjusted Means 1.85 -0.46
95% CI (-0.14, 3.85) (-2.45, 1.54)
p-value 0.0679 0.6539
FATIGI
Adjusted mean
n 134 134 132
Adjusted Mean 5.42 4.83 4.56
Difference in Adjusted Means -0.59 -0.86
95% CI (-2.58, 1.41) (-2.87, 1.15)
p-value 0.5644 0.4026
FKSI-FWB
Adjusted mean
n 134 134 132
Adjusted Mean 4.31 3.53 3.08
Difference in Adjusted Means -0.79 -1.24
95% CI (-2.71, 1.14) (-3.17, 0.69)
p-value 0.4221 0.2088
FKSI-TSE
Adjusted mean
n 134 134 132
Adjusted Mean 4.70 3.84 4.45
Difference in Adjusted Means -0.86 -0.25
95% CI (-2.80, 1.09) (-2.20, 1.70)
p-value 0.3858 0.8007
FKSIALL
Adjusted mean
n 134 134 132
Adjusted Mean 5.00 5.79 6.42
Difference in Adjusted Means 0.79 1.42
95% CI (-1.17, 2.76) (-0.56, 3.39)
p-value 0.4288 0.1591

120 changes: 120 additions & 0 deletions tests/testthat/test-char-support.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
adsl <- random.cdisc.data::cadsl
adeg <- random.cdisc.data::cadeg

################################################################################
# Define script level parameters:
################################################################################
adsl_f <- adsl %>%
select(USUBJID, ACTARM)

# Note: We keep only post-baseline for analysis.
adeg_f <- adeg %>%
filter(AVISIT %in% levels(adeg$AVISIT)[1:3]) %>%
filter(PARAM %in% c("Heart Rate", "QT Duration", "RR Duration")) %>%
var_relabel(
PARAM = "Assessment",
ANRIND = "Abnormality"
) %>%
select(USUBJID, AVISIT, PARAM, PARAMCD, ANRIND, ACTARM) %>%
mutate(PARCAT = case_when(
PARAMCD == "QT" ~ "QT",
TRUE ~ "Other"
)) %>%
mutate(ANRIND2 = paste(ANRIND, PARAMCD)) %>%
mutate(ANRIND3 = paste(ANRIND, PARAM))

# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl_f <- df_explicit_na(adsl_f)
adeg_f <- df_explicit_na(adeg_f)

adeg_f_1 <- adeg_f %>%
filter(PARAMCD != "QT") %>%
mutate(CRITDIR = "Direction 1") %>%
mutate(ANRIND23 = ANRIND2)

adeg_f_2 <- adeg_f %>%
mutate(CRITDIR = "Direction 2") %>%
mutate(ANRIND23 = ANRIND3)

adeg_f <- rbind(adeg_f_1, adeg_f_2)



### mapping dataframe
uniq_adeg <- unique(adeg_f %>% select(PARCAT, PARAMCD, CRITDIR, ANRIND23))
mapdf <- uniq_adeg %>%
arrange(PARCAT, PARAMCD, CRITDIR, ANRIND23) %>%
mutate(across(where(is.factor), as.character))

### 3 versions of dataset
### CRITDIR not factor, all visits have available data for all PARAMCD
adeg_f1 <- adeg_f

### CRITDIR not factor, not all visits available data for all PARAMCD
### exclude QT from screening - this will generate the problem in 6.11
adeg_f <- adeg_f %>%
filter(!(AVISIT == "SCREENING" & PARAMCD == "QT"))

### CRITDIR factor, not all visits available data
adeg_f2 <- adeg_f
### also part of the issue
adeg_f2$CRITDIR <- factor(adeg_f2$CRITDIR)






################################################################################
# Define layout and build table:
################################################################################


lyt <- basic_table(
show_colcounts = TRUE,
colcount_format = "N=xx"
) %>%
split_cols_by("ACTARM") %>%
split_rows_by("AVISIT",
label_pos = "topleft",
section_div = " ",
split_fun = drop_split_levels,
split_label = "Time Point",
child_labels = "visible"
) %>%
split_rows_by("PARAMCD",
split_label = "Test",
label_pos = "topleft",
indent_mod = 1L,
child_labels = "visible",
split_fun = trim_levels_to_map(mapdf)
) %>%
split_rows_by("CRITDIR",
split_label = "Direction",
label_pos = "topleft",
indent_mod = 1L,
child_labels = "visible",
split_fun = trim_levels_to_map(mapdf)
) %>%
analyze(c("ANRIND23"),
a_summary,
extra_args = list(.stats = "count_fraction"),
show_labels = "hidden",
indent_mod = 1L
)

testthat::test_that("CRITDIR is factor, and one PARAMCD is not available on all AVISITS", {
res <- testthat::expect_silent(build_table(lyt, adeg_f2, alt_counts_df = adsl_f))
testthat::expect_snapshot(res)
})


testthat::test_that("CRITDIR is not factor, and all PARAMCD available on all AVISITS", {
res <- testthat::expect_silent(build_table(lyt, adeg_f1, alt_counts_df = adsl_f))
testthat::expect_snapshot(res)
})

testthat::test_that("CRITDIR is not factor, and one PARAMCD is not available on all AVISITS", {
res <- testthat::expect_silent(build_table(lyt, adeg_f, alt_counts_df = adsl_f))
testthat::expect_snapshot(res)
})
1 change: 0 additions & 1 deletion tests/testthat/test-listing_adal02.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ testthat::test_that("ADAL02 listing is produced correctly", {
values_from = AVAL
) %>%
filter(if_any(matches("Treatment Emergent - Positive"), ~ .x == 1)) %>%
# filter(`Treatment Emergent - Positive` == 1) %>%
mutate(
VISN = factor(paste0(
VISIT, "\n(Day ",
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-table_aet04.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ adae <- level_reducer(adae, "AEDECOD", p_to_keep = 0.7)
# Helper function to avoid filtering also the first part of the table, where general information is given.
my_row_condition <- function(row_fnc_condition) {
function(table_row) {
ret <- NULL
if (indent_mod(table_row) == 0) {
return(TRUE)
ret <- TRUE
} else {
row_fnc_condition(table_row)
ret <- row_fnc_condition(table_row)
}
ret
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-table_aovt01.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,23 @@ testthat::test_that("AOVT01 variant with multiple endpoints is produced correctl
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("AOVT01 variant with proportional weights is produced correctly", {
adqs_multi <- dplyr::filter(adqs, AVISIT == "WEEK 1 DAY 8")
n_per_arm <- table(adsl$ARM)

result <- basic_table() %>%
split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>%
add_colcounts() %>%
split_rows_by("PARAMCD") %>%
summarize_ancova(
vars = "CHG",
variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")),
conf_level = 0.95, var_labels = "Adjusted mean",
weights_emmeans = "proportional"
) %>%
build_table(adqs_multi, alt_counts_df = adsl)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})
1 change: 0 additions & 1 deletion tests/testthat/test-table_pkpt04.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ l <- basic_table() %>%
testthat::test_that("PKPT04 is produced correctly for Drug X", {
adpp0 <- adpp_urine %>%
filter(PPCAT == "XANOMELINE") %>%
# h_pkparam_sort() %>%
mutate(PKPARAM = factor(paste0(PPTEST, " (", AVALU, ")")))

result <- build_table(l, df = adpp0)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-table_pkpt05.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ l <- basic_table() %>%
testthat::test_that("PKPT05 Drug X is produced correctly", {
adpp0 <- adpp_urine %>%
filter(PPCAT == "XANOMELINE") %>%
# h_pkparam_sort() %>%
dplyr::mutate(PKPARAM = factor(paste0(PPTEST, " (", AVALU, ")")))
result <- build_table(l, df = adpp0)
main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population")
Expand Down