Skip to content
Closed
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bump flextable and remove the skip() units tests (#193)
- docx exporter added missing defaults (#186)


### Added

- Added option to switch on/off the export of the csv in both `tt_to_tlgrtf()` and `export_as_docx_j()`
Expand Down
70 changes: 37 additions & 33 deletions tests/testthat/test-a_freq_j.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_that("a_freq_j with label_map works in a table layout as expected", {
)
)
result <- build_table(lyt, dta)
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("a_freq_j with label_map restricts the values according to row split and label_map", {
Expand Down Expand Up @@ -48,7 +48,7 @@ test_that("a_freq_j with label_map restricts the values according to row split a
)
)
result <- build_table(lyt, dta)
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("a_freq_j_with_exclude allows to exclude row split levels from the analysis", {
Expand Down Expand Up @@ -78,7 +78,7 @@ test_that("a_freq_j_with_exclude allows to exclude row split levels from the ana
)
result <- build_table(lyt, dta) |>
safe_prune_table(prune_func = tern::keep_rows(keep_non_null_rows))
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("a_freq_j in specific situation error for not passing alt_counts_df", {
Expand Down Expand Up @@ -122,22 +122,22 @@ test_that("a_freq_j in specific situation error for not passing alt_counts_df",
)

result <- build_table(lyt, adsl, alt_counts_df = adsl)
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("a_freq_j in layout with relative risk column for combined facet", {
library(dplyr)
trtvar <- "ARM"
ctrl_grp <- "B: Placebo"

adsl <- ex_adsl |> select(c("USUBJID", "STRATA1", "EOSSTT", all_of(trtvar)))
adsl$colspan_trt <- factor(
ifelse(adsl[[trtvar]] == ctrl_grp, " ", "Active Study Agent"),
levels = c("Active Study Agent", " ")
)
adsl$rrisk_header <- "Risk Difference (%) (95% CI)"
adsl$rrisk_label <- paste(adsl[[trtvar]], paste("vs", ctrl_grp))

colspan_trt_map <- create_colspan_map(
df = adsl,
non_active_grp = ctrl_grp,
Expand All @@ -146,74 +146,78 @@ test_that("a_freq_j in layout with relative risk column for combined facet", {
colspan_var = "colspan_trt",
trt_var = trtvar
)

a_freq_j_args <- list(
.stats = "count_unique_fraction",
ref_path = c("colspan_trt", " ", trtvar, ctrl_grp)
)


# Set up levels and label for the required combined columns
add_combo <- add_combo_facet("Combined",
label = "Combined",
levels = setdiff(unique(adsl[[trtvar]]), ctrl_grp)
add_combo <- add_combo_facet(
"Combined",
label = "Combined",
levels = setdiff(unique(adsl[[trtvar]]), ctrl_grp)
)

# choose if any facets need to be removed - e.g remove the combined column for placebo
rm_combo_from_placebo <- cond_rm_facets(
facets = "Combined",
ancestor_pos = NA,
value = " ",
split = "colspan_trt"
)
mysplit_comb <- make_split_fun(post = list(add_combo, rm_combo_from_placebo))

mysplit_comb <- make_split_fun(post = list(add_combo, rm_combo_from_placebo))

# choose if any facets need to be removed - e.g remove the combined column for placebo
rm_combo_from_placebo2 <- cond_rm_facets(
facets = ctrl_grp,
ancestor_pos = NA,
value = "Risk Difference (%) (95% CI)",
split = "rrisk_header"
)
add_combo2 <- add_combo_facet("Combined",
label = paste0("Combined vs ", ctrl_grp),
levels = setdiff(unique(adsl[[trtvar]]), ctrl_grp)
add_combo2 <- add_combo_facet(
"Combined",
label = paste0("Combined vs ", ctrl_grp),
levels = setdiff(unique(adsl[[trtvar]]), ctrl_grp)
)

mysplit_comb2 <- make_split_fun(post = list(add_combo2, rm_combo_from_placebo2))


lyt <- basic_table(show_colcounts = TRUE) |>
split_cols_by("colspan_trt", split_fun = trim_levels_to_map(map = colspan_trt_map)) |>
split_cols_by(trtvar, split_fun = mysplit_comb) |>
split_cols_by(trtvar, split_fun = mysplit_comb) |>
split_cols_by("rrisk_header", nested = FALSE) |>
split_cols_by(trtvar, labels_var = "rrisk_label", split_fun = mysplit_comb2) |>
split_rows_by("STRATA1") |>
analyze("EOSSTT", afun = a_freq_j, extra_args = a_freq_j_args)


result <- build_table(lyt, adsl, alt_counts_df = adsl)

# confirm column is not NE (NE, NE) and numbers are correct
actual_row <- result[2, ]
actual <- cell_values(result[2, 7])

colcounts <- col_counts(actual_row)

combcols <- 1:2
ctrlcol <- 4
ncolcomb <- sum(colcounts[combcols])
ncolctrl <- colcounts[ctrlcol]

countscomb <- sum(sapply(cell_values(actual_row[1, combcols]), function(v) v[["count_unique"]]), na.rm = TRUE)
countsctrl <- cell_values(actual_row[1, ctrlcol])[[1]][["count_unique"]]

# default method for relative risk in a_freq_j is wald stat which is based upon tern function
expected <- tern::stat_propdiff_ci( x = list(countscomb),
y = list(countsctrl),
N_x = ncolcomb,
N_y = ncolctrl)

expected <- tern::stat_propdiff_ci(
x = list(countscomb),
y = list(countsctrl),
N_x = ncolcomb,
N_y = ncolctrl
)

testthat::expect_equal(actual, expected, ignore_attr = TRUE)
})
8 changes: 4 additions & 4 deletions tests/testthat/test-a_summarize_aval_chg_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test_that("a_summarize_aval_chg_diff_j comp_btw_group = FALSE works as expected"

tbl <- expect_silent(build_table(lyt, advs, alt_counts_df = adsl))
expect_s4_class(tbl, "TableTree")
expect_snapshot(tbl)
expect_snapshot(cran = TRUE, tbl)

# this one also ran fine prior hotfix78
extra_args_3col2 <- list(
Expand All @@ -56,7 +56,7 @@ test_that("a_summarize_aval_chg_diff_j comp_btw_group = FALSE works as expected"

tbl2 <- build_table(lyt2, advs, alt_counts_df = adsl)
expect_s4_class(tbl2, "TableTree")
expect_snapshot(tbl2)
expect_snapshot(cran = TRUE, tbl2)
})

test_that("a_summarize_aval_chg_diff_j t-test sparse data works as expected", {
Expand Down Expand Up @@ -144,11 +144,11 @@ test_that("a_summarize_aval_chg_diff_j t-test sparse data works as expected", {

tbl <- build_table(lyt, advs, alt_counts_df = adsl)
expect_s4_class(tbl, "TableTree")
expect_snapshot(tbl)
expect_snapshot(cran = TRUE, tbl)

tbl2 <- build_table(lyt, advs_2, alt_counts_df = adsl)
expect_s4_class(tbl2, "TableTree")
expect_snapshot(tbl2)
expect_snapshot(cran = TRUE, tbl2)
})


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-blank_line.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test_that("insert_blank_line works as expected", {

# We expect 6 blank lines: after mean and range, for each of the
# 3 STRATA1 levels' row splits.
expect_snapshot(mf_strings(matrix_form(tbl)))
expect_snapshot(cran = TRUE, mf_strings(matrix_form(tbl)))
})

test_that("insert_blank_line optionally uses custom table names", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-cmhrms.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test_that("a_cmhrms_j works in a table layout as expected", {
)
)
res <- expect_silent(build_table(lyt, df = dta))
expect_snapshot(res)
expect_snapshot(cran = TRUE, res)
})

test_that("a_cmhrms_j_with_exclude works in a table layout as expected", {
Expand All @@ -107,5 +107,5 @@ test_that("a_cmhrms_j_with_exclude works in a table layout as expected", {
)
res <- expect_silent(build_table(lyt, df = dta)) |>
safe_prune_table(prune_func = tern::keep_rows(keep_non_null_rows))
expect_snapshot(res)
expect_snapshot(cran = TRUE, res)
})
8 changes: 4 additions & 4 deletions tests/testthat/test-cmp_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("cmp_split_fun works as expected", {
result <- basic_table(round_type = "sas") |>
split_cols_by("ID", split_fun = cmp_split_fun) |>
build_table(formatters::DM)
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("cmp_cfun works correctly for expected column", {
Expand All @@ -17,7 +17,7 @@ test_that("cmp_cfun works correctly for expected column", {
variables = list(expected = "exp", received = "rec", missing = "mis"),
formats = list()
)
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("cmp_cfun works correctly for received column", {
Expand All @@ -35,7 +35,7 @@ test_that("cmp_cfun works correctly for received column", {
variables = list(expected = "exp", received = "rec", missing = "mis"),
formats = list(count_percent = jjcsformat_count_fraction)
)
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("cmp_cfun works correctly for missing column", {
Expand All @@ -54,5 +54,5 @@ test_that("cmp_cfun works correctly for missing column", {
variables = list(expected = "exp", received = "rec", missing = "mis"),
formats = list(count_percent = jjcsformat_count_fraction)
)
expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-colwidths.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ test_that("find_free_colspc works as expected", {

suppressWarnings(result <- find_free_colspc(curposs = curdf, fullposs = full_possdf))

expect_snapshot(result)
expect_snapshot(cran = TRUE, result)
})

test_that("smart_colwidths_1page works as expected", {
Expand Down
Loading
Loading