Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
anajens committed Oct 16, 2023
1 parent 1c39161 commit 7af08d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
17 changes: 9 additions & 8 deletions R/reflast.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,27 @@
#' var_labels = "Survival Time (Months)",
#' is_event = "is_event",
#' ) %>%
#' build_table(df = adtte_f)
#' build_table(df = adtte_f)
#'
ref_group_last <- function(splret, spl, fulldf){

if(!"ref_group_value" %in% slotNames(spl)) {
ref_group_last <- function(splret, spl, fulldf) {
if (!"ref_group_value" %in% slotNames(spl)) {
stop("Reference group is undefined.")
}

spl_var <- spl@payload
init_lvls <- levels(fulldf[[spl_var]])

if(!all(names(splret$values) %in% init_lvls)) {
if (!all(names(splret$values) %in% init_lvls)) {
stop("This split function does not work with combination facets.")
}

ref_group_pos <- which(init_lvls == spl@ref_group_value)
reord_lvls <- c(init_lvls[-ref_group_pos], init_lvls[ref_group_pos])
ord <- match(reord_lvls, names(splret$values))

make_split_result(splret$values[ord],
splret$datasplit[ord],
splret$labels[ord])
make_split_result(
splret$values[ord],
splret$datasplit[ord],
splret$labels[ord]
)
}
24 changes: 5 additions & 19 deletions tests/testthat/test-reflast.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
split_fun <- make_split_fun(post = list(ref_group_last))

testthat::test_that("ref_group_last split fun gives error when ref group is undefined", {

lyt <- basic_table() %>%
split_cols_by(var = "ARMCD", split_fun = split_fun) %>%
analyze("AGE")

testthat::expect_error(build_table(lyt, df = tern_ex_adsl))

})

testthat::test_that("ref_group_last split fun gives error when used with combo facets", {

custom_splitfun <- make_split_fun(
post = list(add_combo_facet("A_C", "Arms A+C", c("A: Drug X", "C: Combination")),
ref_group_last)
post = list(
add_combo_facet("A_C", "Arms A+C", c("A: Drug X", "C: Combination")),
ref_group_last
)
)

lyt <- basic_table() %>%
split_cols_by("ARM", ref_group = "B: Placebo", split_fun = custom_splitfun) %>%
analyze("AGE")

testthat::expect_error(build_table(lyt, df = tern_ex_adsl))

})

testthat::test_that("analyze_vars works as expected with ref_group_last split fun", {

result <- basic_table() %>%
split_cols_by(var = "ARMCD", ref_group = "ARM B", split_fun = split_fun) %>%
add_colcounts() %>%
Expand All @@ -35,11 +32,9 @@ testthat::test_that("analyze_vars works as expected with ref_group_last split fu

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

})

testthat::test_that("compare_vars works as expected with ref_group_last split fun", {

result <- basic_table() %>%
split_cols_by(var = "ARMCD", ref_group = "ARM B", split_fun = split_fun) %>%
add_colcounts() %>%
Expand All @@ -48,11 +43,9 @@ testthat::test_that("compare_vars works as expected with ref_group_last split fu

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

})

testthat::test_that("summarize_ancova works as expected with ref_group_last split fun", {

result <- basic_table() %>%
split_cols_by(var = "ARMCD", ref_group = "ARM B", split_fun = split_fun) %>%
add_colcounts() %>%
Expand All @@ -66,11 +59,9 @@ testthat::test_that("summarize_ancova works as expected with ref_group_last spli

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

})

testthat::test_that("binary endpoint layouts work as expected with ref_group_last split fun", {

adrs_f <- tern_ex_adrs %>%
dplyr::filter(PARAMCD == "INVET") %>%
dplyr::mutate(is_rsp = AVALC %in% c("CR", "PR"))
Expand All @@ -85,11 +76,9 @@ testthat::test_that("binary endpoint layouts work as expected with ref_group_las

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

})

testthat::test_that("time to event layouts works as expected with ref_group_last split fun", {

adtte_f <- tern_ex_adtte %>%
dplyr::filter(PARAMCD == "PFS") %>%
dplyr::mutate(
Expand All @@ -110,16 +99,14 @@ testthat::test_that("time to event layouts works as expected with ref_group_last
time_point = 6,
is_event = "is_event",
method = "both"
)%>%
) %>%
build_table(adtte_f)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

})

testthat::test_that("summarize_ancova works as expected with ref_group_last split fun", {

anl <- tern_ex_adtte %>% filter(PARAMCD == "TNE")

result <- basic_table() %>%
Expand All @@ -139,5 +126,4 @@ testthat::test_that("summarize_ancova works as expected with ref_group_last spli

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

})

0 comments on commit 7af08d2

Please sign in to comment.