From 7af08d2e68d75c3d69e5621b2fffd0c9ac82fc06 Mon Sep 17 00:00:00 2001 From: stoilovs Date: Sun, 15 Oct 2023 21:27:07 -0400 Subject: [PATCH] style --- R/reflast.R | 17 +++++++++-------- tests/testthat/test-reflast.R | 24 +++++------------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/R/reflast.R b/R/reflast.R index b6613ada9c..0257fb3f2d 100644 --- a/R/reflast.R +++ b/R/reflast.R @@ -43,18 +43,17 @@ #' 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.") } @@ -62,7 +61,9 @@ ref_group_last <- function(splret, spl, fulldf){ 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] + ) } diff --git a/tests/testthat/test-reflast.R b/tests/testthat/test-reflast.R index a6e054a09c..b613cc3fcf 100644 --- a/tests/testthat/test-reflast.R +++ b/tests/testthat/test-reflast.R @@ -1,20 +1,19 @@ 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() %>% @@ -22,11 +21,9 @@ testthat::test_that("ref_group_last split fun gives error when used with combo f 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() %>% @@ -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() %>% @@ -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() %>% @@ -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")) @@ -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( @@ -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() %>% @@ -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) - })