From 7bf489e52c40cf11e5d47ff690def9447f7ba21b Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Tue, 3 Sep 2024 11:03:27 +0800 Subject: [PATCH 01/18] update green ci --- DESCRIPTION | 2 +- R/default_split_funs.R | 3 ++- tests/testthat/setup-fakedata.R | 5 ++--- tests/testthat/test-as_html.R | 6 ++++++ tests/testthat/test-formatting.R | 6 ++++++ tests/testthat/test-printing.R | 3 +++ tests/testthat/test-tab_afun_cfun.R | 15 +++++++++++++++ 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 57b77bd71..a9e93db9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ URL: https://github.com/insightsengineering/rtables, https://insightsengineering.github.io/rtables/ BugReports: https://github.com/insightsengineering/rtables/issues Depends: - formatters (>= 0.5.8), + formatters (>= 0.5.8.9006), magrittr (>= 1.5), methods, R (>= 2.10) diff --git a/R/default_split_funs.R b/R/default_split_funs.R index 927079fde..9c9781935 100644 --- a/R/default_split_funs.R +++ b/R/default_split_funs.R @@ -473,7 +473,8 @@ select_all_levels <- new("AllLevelsSentinel") #' @note #' Analysis or summary functions for which the order matters should never be used within the tabulation framework. #' -#' @examples +#' @examplesIf require(tibble) +#' #' library(tibble) #' combodf <- tribble( #' ~valname, ~label, ~levelcombo, ~exargs, diff --git a/tests/testthat/setup-fakedata.R b/tests/testthat/setup-fakedata.R index f22111193..b35e2bb74 100644 --- a/tests/testthat/setup-fakedata.R +++ b/tests/testthat/setup-fakedata.R @@ -1,9 +1,8 @@ ## Loading relevant libraries for tests library(testthat) -library(xml2) -library(tibble) +require(tibble, quietly = TRUE) library(rtables) -library(dplyr) +require(dplyr, quietly = TRUE) # # Load and flag for pdftools to check for it # check_pdf <- require(pdftools) diff --git a/tests/testthat/test-as_html.R b/tests/testthat/test-as_html.R index 405ac3fc1..fa50729e0 100644 --- a/tests/testthat/test-as_html.R +++ b/tests/testthat/test-as_html.R @@ -1,6 +1,9 @@ context("Exporting to HTML") test_that("as_html smoke test", { + require(xml2, quietly = TRUE) + skip_if_not_installed("xml2") + tmpf <- tempfile(fileext = ".html") tbl <- tt_to_export() @@ -114,6 +117,9 @@ test_that("as_html indentation is translated to rows with linebreaks", { }) test_that("as_html expands or not newlines depending on expand_newlines", { + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + # Table with both col/row names with newlines iris_mod <- iris %>% mutate(Species2 = as.factor(paste0("General", "\n ", as.character(Species)))) %>% diff --git a/tests/testthat/test-formatting.R b/tests/testthat/test-formatting.R index de8d5eb25..e927e7bc4 100644 --- a/tests/testthat/test-formatting.R +++ b/tests/testthat/test-formatting.R @@ -135,6 +135,9 @@ test_that("format_na_str functionality works in get_formatted_cells (i.e. printi }) test_that("format and na_str inheritance", { + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + # Test data DM2 <- DM %>% filter(ARM != levels(DM$ARM)[3]) %>% @@ -163,6 +166,9 @@ test_that("format and na_str inheritance", { # Get the ASCII table result <- get_formatted_cells(tbl) # Main function + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + # Expected data-set is built with dplyr expected <- DM2 %>% dplyr::group_by(ARM) %>% diff --git a/tests/testthat/test-printing.R b/tests/testthat/test-printing.R index 7c6398b34..6cc5bdf08 100644 --- a/tests/testthat/test-printing.R +++ b/tests/testthat/test-printing.R @@ -555,6 +555,9 @@ test_that("Cell and column label wrapping works in printing", { test_that("row label indentation is kept even if there are newline characters", { + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + ANL <- DM %>% mutate(value = rnorm(n()), pctdiff = runif(n())) %>% filter(ARM == "A: Drug X") diff --git a/tests/testthat/test-tab_afun_cfun.R b/tests/testthat/test-tab_afun_cfun.R index 594afdeed..1b33d59ba 100644 --- a/tests/testthat/test-tab_afun_cfun.R +++ b/tests/testthat/test-tab_afun_cfun.R @@ -1,6 +1,9 @@ context("Analysis functions (afun)") test_that(".spl_context contains information about the column split", { + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + ## Duplication hack -> This would need to use split_cols_by_multivar(...) # Workaround for #690 DM_tmp <- DM %>% @@ -39,6 +42,12 @@ test_that(".spl_context contains information about the column split", { }) test_that(".spl_context and afun extra parameters contain information about combo counts", { + require(tibble, quietly = TRUE) + skip_if_not_installed("tibble") + + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + ## Fix for https://github.com/insightsengineering/rtables/issues/517 combodf <- tribble( ~valname, ~label, ~levelcombo, ~exargs, @@ -217,6 +226,9 @@ test_that("Error localization for missing split variable when done in alt_count_ }) test_that("Error localization for missmatch split variable when done in alt_count_df", { + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + afun_tmp <- function(x, .alt_df_row, .spl_context, ...) { # Important check that order is aligned even if source levels are not check_val <- unique(.alt_df_row$ARMCD) @@ -281,6 +293,9 @@ test_that("Error localization for missmatch split variable when done in alt_coun context("Content functions (cfun)") test_that(".alt_df_row appears in cfun but not in afun.", { + require(dplyr, quietly = TRUE) + skip_if_not_installed("dplyr") + # Adding STRATA2 col to DM for alt_counts_df col split alt_tmp <- DM %>% left_join( ex_adsl %>% From 13b1cd6b974f59c31db6c20ef65a781b481345eb Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 03:06:05 +0000 Subject: [PATCH 02/18] [skip style] [skip vbump] Restyle files --- R/default_split_funs.R | 2 +- tests/testthat/test-as_html.R | 4 ++-- tests/testthat/test-formatting.R | 4 ++-- tests/testthat/test-printing.R | 2 +- tests/testthat/test-tab_afun_cfun.R | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R/default_split_funs.R b/R/default_split_funs.R index 9c9781935..4480805a9 100644 --- a/R/default_split_funs.R +++ b/R/default_split_funs.R @@ -474,7 +474,7 @@ select_all_levels <- new("AllLevelsSentinel") #' Analysis or summary functions for which the order matters should never be used within the tabulation framework. #' #' @examplesIf require(tibble) -#' +#' #' library(tibble) #' combodf <- tribble( #' ~valname, ~label, ~levelcombo, ~exargs, diff --git a/tests/testthat/test-as_html.R b/tests/testthat/test-as_html.R index fa50729e0..0d9d599ec 100644 --- a/tests/testthat/test-as_html.R +++ b/tests/testthat/test-as_html.R @@ -3,7 +3,7 @@ context("Exporting to HTML") test_that("as_html smoke test", { require(xml2, quietly = TRUE) skip_if_not_installed("xml2") - + tmpf <- tempfile(fileext = ".html") tbl <- tt_to_export() @@ -119,7 +119,7 @@ test_that("as_html indentation is translated to rows with linebreaks", { test_that("as_html expands or not newlines depending on expand_newlines", { require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + # Table with both col/row names with newlines iris_mod <- iris %>% mutate(Species2 = as.factor(paste0("General", "\n ", as.character(Species)))) %>% diff --git a/tests/testthat/test-formatting.R b/tests/testthat/test-formatting.R index e927e7bc4..81418d9a6 100644 --- a/tests/testthat/test-formatting.R +++ b/tests/testthat/test-formatting.R @@ -137,7 +137,7 @@ test_that("format_na_str functionality works in get_formatted_cells (i.e. printi test_that("format and na_str inheritance", { require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + # Test data DM2 <- DM %>% filter(ARM != levels(DM$ARM)[3]) %>% @@ -168,7 +168,7 @@ test_that("format and na_str inheritance", { require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + # Expected data-set is built with dplyr expected <- DM2 %>% dplyr::group_by(ARM) %>% diff --git a/tests/testthat/test-printing.R b/tests/testthat/test-printing.R index 6cc5bdf08..0a1b95e5c 100644 --- a/tests/testthat/test-printing.R +++ b/tests/testthat/test-printing.R @@ -557,7 +557,7 @@ test_that("Cell and column label wrapping works in printing", { test_that("row label indentation is kept even if there are newline characters", { require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + ANL <- DM %>% mutate(value = rnorm(n()), pctdiff = runif(n())) %>% filter(ARM == "A: Drug X") diff --git a/tests/testthat/test-tab_afun_cfun.R b/tests/testthat/test-tab_afun_cfun.R index 1b33d59ba..33532ebe9 100644 --- a/tests/testthat/test-tab_afun_cfun.R +++ b/tests/testthat/test-tab_afun_cfun.R @@ -3,7 +3,7 @@ context("Analysis functions (afun)") test_that(".spl_context contains information about the column split", { require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + ## Duplication hack -> This would need to use split_cols_by_multivar(...) # Workaround for #690 DM_tmp <- DM %>% @@ -44,10 +44,10 @@ test_that(".spl_context contains information about the column split", { test_that(".spl_context and afun extra parameters contain information about combo counts", { require(tibble, quietly = TRUE) skip_if_not_installed("tibble") - + require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + ## Fix for https://github.com/insightsengineering/rtables/issues/517 combodf <- tribble( ~valname, ~label, ~levelcombo, ~exargs, @@ -228,7 +228,7 @@ test_that("Error localization for missing split variable when done in alt_count_ test_that("Error localization for missmatch split variable when done in alt_count_df", { require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + afun_tmp <- function(x, .alt_df_row, .spl_context, ...) { # Important check that order is aligned even if source levels are not check_val <- unique(.alt_df_row$ARMCD) @@ -295,7 +295,7 @@ context("Content functions (cfun)") test_that(".alt_df_row appears in cfun but not in afun.", { require(dplyr, quietly = TRUE) skip_if_not_installed("dplyr") - + # Adding STRATA2 col to DM for alt_counts_df col split alt_tmp <- DM %>% left_join( ex_adsl %>% From a18b8a8c79087e75e798b68cedbc668b558e689e Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 03:09:37 +0000 Subject: [PATCH 03/18] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/add_overall_level.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/man/add_overall_level.Rd b/man/add_overall_level.Rd index 1cb231236..ce22160ca 100644 --- a/man/add_overall_level.Rd +++ b/man/add_overall_level.Rd @@ -78,6 +78,8 @@ lyt2 tbl2 <- build_table(lyt2, DM) tbl2 +\dontshow{if (require(tibble)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} + library(tibble) combodf <- tribble( ~valname, ~label, ~levelcombo, ~exargs, @@ -125,7 +127,7 @@ lyt3 <- basic_table(show_colcounts = TRUE) \%>\% tbl3 <- build_table(lyt3, smallerDM) tbl3 - +\dontshow{\}) # examplesIf} } \seealso{ \link{custom_split_funs} and \link{split_funcs}. From fa6ebf13ce2f5433dc86bf9094bdb2d7532e1ff1 Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Tue, 3 Sep 2024 11:15:53 +0800 Subject: [PATCH 04/18] update doc --- man/add_overall_level.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/man/add_overall_level.Rd b/man/add_overall_level.Rd index 1cb231236..ce22160ca 100644 --- a/man/add_overall_level.Rd +++ b/man/add_overall_level.Rd @@ -78,6 +78,8 @@ lyt2 tbl2 <- build_table(lyt2, DM) tbl2 +\dontshow{if (require(tibble)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} + library(tibble) combodf <- tribble( ~valname, ~label, ~levelcombo, ~exargs, @@ -125,7 +127,7 @@ lyt3 <- basic_table(show_colcounts = TRUE) \%>\% tbl3 <- build_table(lyt3, smallerDM) tbl3 - +\dontshow{\}) # examplesIf} } \seealso{ \link{custom_split_funs} and \link{split_funcs}. From 99c53fbb0e24c592769e116c1f8d7d124b724501 Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Tue, 3 Sep 2024 13:32:15 +0800 Subject: [PATCH 05/18] tidy up code --- tests/testthat/setup-fakedata.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/testthat/setup-fakedata.R b/tests/testthat/setup-fakedata.R index b35e2bb74..52384d1c5 100644 --- a/tests/testthat/setup-fakedata.R +++ b/tests/testthat/setup-fakedata.R @@ -163,9 +163,7 @@ tt_to_export <- export_fact() # Creating data-set with wide content to test wrapping tt_to_test_wrapping <- function() { - trimmed_data <- ex_adsl %>% - filter(SEX %in% c("M", "F")) %>% - filter(RACE %in% levels(RACE)[1:2]) + trimmed_data <- ex_adsl[(ex_adsl$SEX %in% c("M", "F")) & c(ex_adsl$RACE %in% levels(ex_adsl$RACE)[1:2]),] levels(trimmed_data$ARM)[1] <- "Incredibly long column name to be wrapped" levels(trimmed_data$ARM)[2] <- "This_should_be_somewhere_split" From b5d67ee0ff993f5f7261aca8ae4d0bca7c77bc55 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 05:34:40 +0000 Subject: [PATCH 06/18] [skip style] [skip vbump] Restyle files --- tests/testthat/setup-fakedata.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/setup-fakedata.R b/tests/testthat/setup-fakedata.R index 52384d1c5..9197c0b4d 100644 --- a/tests/testthat/setup-fakedata.R +++ b/tests/testthat/setup-fakedata.R @@ -163,7 +163,7 @@ tt_to_export <- export_fact() # Creating data-set with wide content to test wrapping tt_to_test_wrapping <- function() { - trimmed_data <- ex_adsl[(ex_adsl$SEX %in% c("M", "F")) & c(ex_adsl$RACE %in% levels(ex_adsl$RACE)[1:2]),] + trimmed_data <- ex_adsl[(ex_adsl$SEX %in% c("M", "F")) & c(ex_adsl$RACE %in% levels(ex_adsl$RACE)[1:2]), ] levels(trimmed_data$ARM)[1] <- "Incredibly long column name to be wrapped" levels(trimmed_data$ARM)[2] <- "This_should_be_somewhere_split" From ca758e8b1bf7b4996f80dc53ed1d959be58c67ae Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Tue, 3 Sep 2024 13:37:19 +0800 Subject: [PATCH 07/18] Empty-Commit From 13d779651112ff2a4f54a5aab4911c905462109e Mon Sep 17 00:00:00 2001 From: Davide Garolini Date: Tue, 3 Sep 2024 15:17:38 +0200 Subject: [PATCH 08/18] Update tests/testthat/setup-fakedata.R Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Signed-off-by: Davide Garolini --- tests/testthat/setup-fakedata.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/setup-fakedata.R b/tests/testthat/setup-fakedata.R index 9197c0b4d..fac12a4f8 100644 --- a/tests/testthat/setup-fakedata.R +++ b/tests/testthat/setup-fakedata.R @@ -1,7 +1,6 @@ ## Loading relevant libraries for tests library(testthat) require(tibble, quietly = TRUE) -library(rtables) require(dplyr, quietly = TRUE) # # Load and flag for pdftools to check for it From 637d61d1a4d61e7ae088fc88d3f212bf46eefb65 Mon Sep 17 00:00:00 2001 From: Davide Garolini Date: Tue, 3 Sep 2024 15:17:51 +0200 Subject: [PATCH 09/18] Update tests/testthat/setup-fakedata.R Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Signed-off-by: Davide Garolini --- tests/testthat/setup-fakedata.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/setup-fakedata.R b/tests/testthat/setup-fakedata.R index fac12a4f8..a7721e54d 100644 --- a/tests/testthat/setup-fakedata.R +++ b/tests/testthat/setup-fakedata.R @@ -1,5 +1,4 @@ ## Loading relevant libraries for tests -library(testthat) require(tibble, quietly = TRUE) require(dplyr, quietly = TRUE) From a8f8f2fdd3d4ca10e93d01e2bdf6a5f80e06d388 Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Fri, 6 Sep 2024 11:53:54 +0800 Subject: [PATCH 10/18] update green ci --- R/colby_constructors.R | 10 ++++--- R/summary.R | 6 ++--- R/tt_pos_and_access.R | 1 + R/tt_toString.R | 8 +++--- man/analyze_colvars.Rd | 3 ++- man/append_topleft.Rd | 3 ++- man/cell_values.Rd | 3 ++- man/gfc.Rd | 3 ++- man/int_methods.Rd | 3 ++- man/matrix_form-VTableTree-method.Rd | 3 ++- man/row_paths_summary.Rd | 3 ++- man/split_cols_by.Rd | 3 ++- man/split_cols_by_multivar.Rd | 3 ++- man/split_rows_by.Rd | 3 ++- man/table_shell.Rd | 3 ++- man/table_structure.Rd | 3 ++- man/tostring.Rd | 3 ++- man/varcuts.Rd | 3 ++- tests/testthat/setup-fakedata.R | 8 +++--- vignettes/clinical_trials.Rmd | 14 ++++++++++ vignettes/col_counts.Rmd | 20 +++++++++++--- vignettes/custom_appearance.Rmd | 15 +++++++++++ vignettes/example_analysis_coxreg.Rmd | 16 ++++++++++- vignettes/exploratory_analysis.Rmd | 14 ++++++++++ vignettes/introspecting_tables.Rmd | 38 ++++++++++++++++++--------- vignettes/rtables.Rmd | 14 ++++++++++ vignettes/sorting_pruning.Rmd | 22 +++++++++++++--- vignettes/subsetting_tables.Rmd | 21 ++++++++++++--- vignettes/tabulation_concepts.Rmd | 14 ++++++++++ vignettes/tabulation_dplyr.Rmd | 18 ++++++++++--- vignettes/title_footer.Rmd | 16 ++++++++++- 31 files changed, 240 insertions(+), 57 deletions(-) diff --git a/R/colby_constructors.R b/R/colby_constructors.R index b68836c5d..d23d243a1 100644 --- a/R/colby_constructors.R +++ b/R/colby_constructors.R @@ -312,6 +312,7 @@ setMethod( #' tbl2 <- build_table(lyt2, DM) #' tbl2 #' +#' @examplesIf require(dplyr) #' # By default sequentially adding layouts results in nesting #' library(dplyr) #' @@ -472,6 +473,7 @@ setMethod( #' #' lyt3 #' +#' @examplesIf require(dplyr) #' library(dplyr) #' #' DM2 <- DM %>% @@ -548,7 +550,7 @@ split_rows_by <- function(lyt, #' #' @seealso [analyze_colvars()] #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' ANL <- DM %>% mutate(value = rnorm(n()), pctdiff = runif(n())) @@ -661,7 +663,7 @@ split_rows_by_multivar <- function(lyt, #' #' @inherit split_cols_by return #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' # split_cols_by_cuts @@ -1188,7 +1190,7 @@ get_acolvar_vars <- function(lyt) { #' #' @seealso [split_cols_by_multivar()] #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' ANL <- DM %>% mutate(value = rnorm(n()), pctdiff = runif(n())) @@ -2117,7 +2119,7 @@ basic_table <- function(title = "", #' #' @seealso [top_left()] #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' DM2 <- DM %>% mutate(RACE = factor(RACE), SEX = factor(SEX)) diff --git a/R/summary.R b/R/summary.R index a6d45da51..99f0b7e3d 100644 --- a/R/summary.R +++ b/R/summary.R @@ -43,7 +43,7 @@ col_paths <- function(x) { #' #' @return A data frame summarizing the row- or column-structure of `x`. #' -#' @examples +#' @examplesIf require(dplyr) #' ex_adsl_MF <- ex_adsl %>% dplyr::filter(SEX %in% c("M", "F")) #' #' lyt <- basic_table() %>% @@ -155,7 +155,7 @@ col_paths_summary <- function(x) { #' @param depth (`numeric(1)`)\cr depth. #' @param indent (`numeric(1)`)\cr indent. #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' iris2 <- iris %>% @@ -234,7 +234,7 @@ setMethod( #' #' @return No return value. Called for the side-effect of printing a row- or subtable-structure summary of `x`. #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' iris2 <- iris %>% diff --git a/R/tt_pos_and_access.R b/R/tt_pos_and_access.R index b914fb364..127f678c9 100644 --- a/R/tt_pos_and_access.R +++ b/R/tt_pos_and_access.R @@ -1228,6 +1228,7 @@ setMethod( #' split_rows_by("STRATA1") %>% #' analyze("AGE") #' +#' @examplesIf require(dplyr) #' library(dplyr) ## for mutate #' tbl <- build_table(lyt, DM %>% #' mutate(SEX = droplevels(SEX), RACE = droplevels(RACE))) diff --git a/R/tt_toString.R b/R/tt_toString.R index 0b387cda6..dbca92e7e 100644 --- a/R/tt_toString.R +++ b/R/tt_toString.R @@ -21,7 +21,7 @@ NULL #' #' @return A string representation of `x` as it appears when printed. #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' iris2 <- iris %>% @@ -80,7 +80,7 @@ setMethod("toString", "VTableTree", function(x, #' #' @seealso [value_formats()] for a matrix of formats for each cell in a table. #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' iris2 <- iris %>% @@ -174,7 +174,7 @@ table_shell_str <- function(tt, widths = NULL, col_gap = 3, hsep = default_hsep( #' #' With an additional `nrow_header` attribute indicating the number of pseudo "rows" that the column structure defines. #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' iris2 <- iris %>% @@ -646,7 +646,7 @@ get_formatted_fnotes <- function(tt) { #' #' @return The formatted print-strings for all (body) cells in `obj`. #' -#' @examples +#' @examplesIf require(dplyr) #' library(dplyr) #' #' iris2 <- iris %>% diff --git a/man/analyze_colvars.Rd b/man/analyze_colvars.Rd index 70a3bf65b..3740174dc 100644 --- a/man/analyze_colvars.Rd +++ b/man/analyze_colvars.Rd @@ -51,6 +51,7 @@ A \code{PreDataTableLayouts} object suitable for passing to further layouting fu Generate rows analyzing different variables across columns } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) ANL <- DM \%>\% mutate(value = rnorm(n()), pctdiff = runif(n())) @@ -90,7 +91,7 @@ lyt2 <- basic_table() \%>\% tbl2 <- build_table(lyt2, ANL) tbl2 - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=split_cols_by_multivar]{split_cols_by_multivar()}} diff --git a/man/append_topleft.Rd b/man/append_topleft.Rd index 4b57764b6..0db619506 100644 --- a/man/append_topleft.Rd +++ b/man/append_topleft.Rd @@ -31,6 +31,7 @@ the actual splitting keywords. This may change in the future. This function is experimental, its name and the details of its behavior are subject to change in future versions. } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) DM2 <- DM \%>\% mutate(RACE = factor(RACE), SEX = factor(SEX)) @@ -45,7 +46,7 @@ lyt <- basic_table() \%>\% tbl <- build_table(lyt, DM2) tbl - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=top_left]{top_left()}} diff --git a/man/cell_values.Rd b/man/cell_values.Rd index 34ab79c07..1082f52f3 100644 --- a/man/cell_values.Rd +++ b/man/cell_values.Rd @@ -47,6 +47,7 @@ lyt <- basic_table() \%>\% split_rows_by("STRATA1") \%>\% analyze("AGE") +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) ## for mutate tbl <- build_table(lyt, DM \%>\% mutate(SEX = droplevels(SEX), RACE = droplevels(RACE))) @@ -94,5 +95,5 @@ cvnolist <- value_at( c("ARM", "B: Placebo", "SEX", "M") ) stopifnot(identical(cvlist[[1]], cvnolist)) - +\dontshow{\}) # examplesIf} } diff --git a/man/gfc.Rd b/man/gfc.Rd index 3755f424d..f5e2d33da 100644 --- a/man/gfc.Rd +++ b/man/gfc.Rd @@ -46,6 +46,7 @@ The formatted print-strings for all (body) cells in \code{obj}. Get formatted cells } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) iris2 <- iris \%>\% @@ -60,5 +61,5 @@ tbl <- basic_table() \%>\% build_table(iris2) get_formatted_cells(tbl) - +\dontshow{\}) # examplesIf} } diff --git a/man/int_methods.Rd b/man/int_methods.Rd index d62765a9a..16ea11304 100644 --- a/man/int_methods.Rd +++ b/man/int_methods.Rd @@ -1272,6 +1272,7 @@ These are internal methods that are documented only to satisfy \verb{R CMD check attention to this documentation. } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) iris2 <- iris \%>\% @@ -1288,7 +1289,7 @@ lyt <- basic_table() \%>\% ) tbl <- build_table(lyt, iris2) - +\dontshow{\}) # examplesIf} indent_mod(tbl) indent_mod(tbl) <- 1L tbl diff --git a/man/matrix_form-VTableTree-method.Rd b/man/matrix_form-VTableTree-method.Rd index 39a9e6a66..9e3776a39 100644 --- a/man/matrix_form-VTableTree-method.Rd +++ b/man/matrix_form-VTableTree-method.Rd @@ -55,6 +55,7 @@ values are determined using \code{get_formatted_cells}. (Column labels are calcu function. } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) iris2 <- iris \%>\% @@ -74,5 +75,5 @@ lyt tbl <- build_table(lyt, iris2) matrix_form(tbl) - +\dontshow{\}) # examplesIf} } diff --git a/man/row_paths_summary.Rd b/man/row_paths_summary.Rd index fc8c54746..5a2ec27fc 100644 --- a/man/row_paths_summary.Rd +++ b/man/row_paths_summary.Rd @@ -19,6 +19,7 @@ A data frame summarizing the row- or column-structure of \code{x}. Print row/column paths summary } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ex_adsl_MF <- ex_adsl \%>\% dplyr::filter(SEX \%in\% c("M", "F")) lyt <- basic_table() \%>\% @@ -46,5 +47,5 @@ tbl2 <- rtable( rrow("r1", 1, 2, 1, 2), rrow("r2", 3, 4, 2, 1) ) col_paths_summary(tbl2) - +\dontshow{\}) # examplesIf} } diff --git a/man/split_cols_by.Rd b/man/split_cols_by.Rd index 98bcffc89..b36e31bfb 100644 --- a/man/split_cols_by.Rd +++ b/man/split_cols_by.Rd @@ -120,6 +120,7 @@ lyt2 tbl2 <- build_table(lyt2, DM) tbl2 +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # By default sequentially adding layouts results in nesting library(dplyr) @@ -160,7 +161,7 @@ lyt5 tbl5 <- build_table(lyt5, DM) tbl5 - +\dontshow{\}) # examplesIf} } \author{ Gabriel Becker diff --git a/man/split_cols_by_multivar.Rd b/man/split_cols_by_multivar.Rd index e1c108319..75fd2a752 100644 --- a/man/split_cols_by_multivar.Rd +++ b/man/split_cols_by_multivar.Rd @@ -53,6 +53,7 @@ When we need columns to reflect different variables entirely, rather than differ variable, we use \code{split_cols_by_multivar}. } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) ANL <- DM \%>\% mutate(value = rnorm(n()), pctdiff = runif(n())) @@ -77,7 +78,7 @@ lyt tbl <- build_table(lyt, ANL) tbl - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=analyze_colvars]{analyze_colvars()}} diff --git a/man/split_rows_by.Rd b/man/split_rows_by.Rd index bb334b4b3..abf3ed1e0 100644 --- a/man/split_rows_by.Rd +++ b/man/split_rows_by.Rd @@ -140,6 +140,7 @@ lyt3 <- basic_table() \%>\% lyt3 +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) DM2 <- DM \%>\% @@ -165,7 +166,7 @@ DM2 <- DM \%>\% tbl3 <- build_table(lyt3, DM2) tbl3 - +\dontshow{\}) # examplesIf} } \author{ Gabriel Becker diff --git a/man/table_shell.Rd b/man/table_shell.Rd index 6be8499db..17734b69c 100644 --- a/man/table_shell.Rd +++ b/man/table_shell.Rd @@ -54,6 +54,7 @@ A table shell is a rendering of the table which maintains the structure, but doe displaying the formatting instructions for each cell. } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) iris2 <- iris \%>\% @@ -68,7 +69,7 @@ lyt <- basic_table() \%>\% tbl <- build_table(lyt, iris2) table_shell(tbl) - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=value_formats]{value_formats()}} for a matrix of formats for each cell in a table. diff --git a/man/table_structure.Rd b/man/table_structure.Rd index a8c344d8a..f241b36e0 100644 --- a/man/table_structure.Rd +++ b/man/table_structure.Rd @@ -18,6 +18,7 @@ No return value. Called for the side-effect of printing a row- or subtable-struc Summarize table } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) iris2 <- iris \%>\% @@ -41,5 +42,5 @@ row_paths(tbl) table_structure(tbl) table_structure(tbl, detail = "row") - +\dontshow{\}) # examplesIf} } diff --git a/man/tostring.Rd b/man/tostring.Rd index a6e1933c1..0906e9882 100644 --- a/man/tostring.Rd +++ b/man/tostring.Rd @@ -64,6 +64,7 @@ undefined wrapping behavior. Passing vectors of already split strings remains su case each string is word-wrapped separately with the behavior described above. } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) iris2 <- iris \%>\% @@ -79,7 +80,7 @@ lyt <- basic_table() \%>\% tbl <- build_table(lyt, iris2) cat(toString(tbl, col_gap = 3)) - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[formatters:wrap_string]{wrap_string()}} diff --git a/man/varcuts.Rd b/man/varcuts.Rd index e85079448..abca48304 100644 --- a/man/varcuts.Rd +++ b/man/varcuts.Rd @@ -160,6 +160,7 @@ before proceeding. Thus even when nested within another split in column/row spac the overall values (e.g., quartiles) in the dataset, NOT the values for subset it is nested under. } \examples{ +\dontshow{if (require(dplyr)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) # split_cols_by_cuts @@ -239,7 +240,7 @@ lyt6 <- basic_table() \%>\% tbl6 <- build_table(lyt6, ex_adsl) tbl6 - +\dontshow{\}) # examplesIf} } \author{ Gabriel Becker diff --git a/tests/testthat/setup-fakedata.R b/tests/testthat/setup-fakedata.R index a7721e54d..023dd0159 100644 --- a/tests/testthat/setup-fakedata.R +++ b/tests/testthat/setup-fakedata.R @@ -183,11 +183,11 @@ tt_for_wrap <- tt_to_test_wrapping() tt_to_test_newline_chars <- function() { set.seed(1) - DM_trick <- DM %>% - mutate(ARM = "ARM \n\nA\n") %>% - mutate(ARM2 = sample(c("TWO\nwords\n ", "A wo\n\nrd\n\n"), + DM_trick <- DM + DM_trick$ARM = "ARM \n\nA\n" + DM_trick$ARM2 = sample(c("TWO\nwords\n ", "A wo\n\nrd\n\n"), replace = TRUE, nrow(DM) - )) # last \n is eaten up if no empty space + ) # last \n is eaten up if no empty space levels(DM_trick$SEX)[3] <- "U\nN\nD\n" tbl <- basic_table() %>% split_rows_by("SEX", diff --git a/vignettes/clinical_trials.Rmd b/vignettes/clinical_trials.Rmd index ac06490ac..03219b27d 100644 --- a/vignettes/clinical_trials.Rmd +++ b/vignettes/clinical_trials.Rmd @@ -11,6 +11,20 @@ editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") ``` diff --git a/vignettes/col_counts.Rmd b/vignettes/col_counts.Rmd index 5f0240100..289c8c09e 100644 --- a/vignettes/col_counts.Rmd +++ b/vignettes/col_counts.Rmd @@ -11,6 +11,20 @@ editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") ``` @@ -81,7 +95,7 @@ label (spanning the same number of rows) when set to be visible. ## Setting Column Counts to Visible at Layout Time -The primary way for users to create tables which displays these "high-level" +The primary way for users to create tables which displays these "high-level" column counts is to create a layout that specifies they should be visible. We do this with the new `show_colcounts` argument now accepted by all @@ -112,7 +126,7 @@ tbl3 <- build_table(lyt3, ex_adsl) tbl3 ``` -As before, these column counts are calculated at table creation time, using +As before, these column counts are calculated at table creation time, using `alt_counts_df` if it is provided (or simply `df` otherwise). Column formats are set at layout time via the `colcount_format` argument @@ -134,7 +148,7 @@ facets. ### Setting individual column counts -The `facet_colcount` getter and setter queries and sets the column count for a facet in column space (note it needs not be a leaf facet). E.g., +The `facet_colcount` getter and setter queries and sets the column count for a facet in column space (note it needs not be a leaf facet). E.g., ```{r} facet_colcount(tbl3, c("ARM", "C: Combination")) diff --git a/vignettes/custom_appearance.Rmd b/vignettes/custom_appearance.Rmd index 1b873ba3f..eac4b91e9 100644 --- a/vignettes/custom_appearance.Rmd +++ b/vignettes/custom_appearance.Rmd @@ -11,6 +11,21 @@ editor_options: chunk_output_type: console --- + +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") ``` diff --git a/vignettes/example_analysis_coxreg.Rmd b/vignettes/example_analysis_coxreg.Rmd index f5105fc25..fd74fbabd 100644 --- a/vignettes/example_analysis_coxreg.Rmd +++ b/vignettes/example_analysis_coxreg.Rmd @@ -7,10 +7,24 @@ vignette: > %\VignetteEncoding{UTF-8} %\VignetteIndexEntry{Example Complex Analysis Function: Modelling Cox Regression} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ## Introduction In this vignette we will demonstrate how a complex analysis function can be constructed in order to build highly-customized tables with `rtables`. This example will detail the steps in creating an analysis function to calculate a basic univariable Cox regression summary table to analyze the treatment effect of the `ARM` variable and any covariate/interaction effects for a survival analysis. For a Cox regression analysis function with more customization options and the capability of fitting multivariable Cox regression models, see the [`summarize_coxreg()`](https://insightsengineering.github.io/tern/main/reference/cox_regression.html) function from the [`tern`](https://insightsengineering.github.io/tern/main/index.html) package, which builds upon the concepts used in the construction of this example. diff --git a/vignettes/exploratory_analysis.Rmd b/vignettes/exploratory_analysis.Rmd index b9ba0e2ae..51e55a305 100644 --- a/vignettes/exploratory_analysis.Rmd +++ b/vignettes/exploratory_analysis.Rmd @@ -11,6 +11,20 @@ editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") ``` diff --git a/vignettes/introspecting_tables.Rmd b/vignettes/introspecting_tables.Rmd index 76a56fb2d..98ca6e643 100644 --- a/vignettes/introspecting_tables.Rmd +++ b/vignettes/introspecting_tables.Rmd @@ -7,10 +7,24 @@ vignette: > %\VignetteIndexEntry{Introspecting Tables} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") ``` @@ -77,8 +91,8 @@ coltree_structure(tbl) Further information about the column structure can be found in the vignette on [`col_counts`](https://insightsengineering.github.io/rtables/latest-tag/articles/col_counts.html). -The `make_row_df()` and `make_col_df()` functions each create a `data.frame` with a variety of information about -the table's structure. Most useful for introspection purposes are the `label`, `name`, `abs_rownumber`, `path` and +The `make_row_df()` and `make_col_df()` functions each create a `data.frame` with a variety of information about +the table's structure. Most useful for introspection purposes are the `label`, `name`, `abs_rownumber`, `path` and `node_class` columns (the remainder of the information in the returned `data.frame` is used for pagination) ```{r} @@ -91,16 +105,16 @@ There is also a wrapper function, `row_paths()` available for `make_row_df` to d row_paths(tbl) ``` -By default `make_row_df()` summarizes only visible rows, but setting `visible_only` to `FALSE` gives us a structural -summary of the table with the full hierarchy of subtables, including those that are not represented directly by any +By default `make_row_df()` summarizes only visible rows, but setting `visible_only` to `FALSE` gives us a structural +summary of the table with the full hierarchy of subtables, including those that are not represented directly by any visible rows: ```{r} make_row_df(tbl, visible_only = FALSE)[, c("label", "name", "abs_rownumber", "path", "node_class")] ``` -`make_col_df()` similarly accepts `visible_only`, though here the meaning is slightly different, indicating whether -only *leaf* columns should be summarized (defaults to `TRUE`) or whether higher level groups of columns - analogous to +`make_col_df()` similarly accepts `visible_only`, though here the meaning is slightly different, indicating whether +only *leaf* columns should be summarized (defaults to `TRUE`) or whether higher level groups of columns - analogous to subtables in row space - should be summarized as well. ```{r} @@ -117,8 +131,8 @@ Similarly, there is wrapper function `col_paths()` available, which displays onl col_paths(tbl) ``` -The `row_paths_summary()` and `col_paths_summary()` functions wrap the respective `make_*_df` functions, printing the -`name`, `node_class`, and `path` information (in the row case), or the `label` and `path` information (in the column +The `row_paths_summary()` and `col_paths_summary()` functions wrap the respective `make_*_df` functions, printing the +`name`, `node_class`, and `path` information (in the row case), or the `label` and `path` information (in the column case), indented to illustrate table structure: ```{r} @@ -145,15 +159,15 @@ value_formats(tbl) ## Applications -Knowing the structure of an `rtable` object is helpful for retrieving specific values from the table. +Knowing the structure of an `rtable` object is helpful for retrieving specific values from the table. For examples, see the [Path Based Cell Value Accessing](https://insightsengineering.github.io/rtables/latest-tag/articles/subsetting_tables.html#path-based-cell-value-accessing) section of the Subsetting and Manipulating Table Contents vignette. -Understanding table structure is also important for post-processing processes such as sorting and pruning. More details +Understanding table structure is also important for post-processing processes such as sorting and pruning. More details on this are covered in the [Pruning and Sorting Tables vignette](https://insightsengineering.github.io/rtables/latest-tag/articles/sorting_pruning.html) vignette. ## Summary -In this vignette you have learned a number of utility functions that are available for examining the underlying +In this vignette you have learned a number of utility functions that are available for examining the underlying structure of `rtable` objects. diff --git a/vignettes/rtables.Rmd b/vignettes/rtables.Rmd index 00b5f9865..1eb3e897f 100644 --- a/vignettes/rtables.Rmd +++ b/vignettes/rtables.Rmd @@ -11,6 +11,20 @@ editor_options: chunk_output_type: console --- + +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") ``` diff --git a/vignettes/sorting_pruning.Rmd b/vignettes/sorting_pruning.Rmd index c23113f73..2b3b6fdda 100644 --- a/vignettes/sorting_pruning.Rmd +++ b/vignettes/sorting_pruning.Rmd @@ -7,10 +7,24 @@ vignette: > %\VignetteIndexEntry{Pruning and Sorting Tables} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") ``` @@ -104,7 +118,7 @@ of the table that is split (with `split_rows_by("RACE") %>%`) into two subtables: `[TableTree] ASIAN [cont: 1 x 6]` and `[TableTree] BLACK OR AFRICAN AMERICAN [cont: 1 x 6]`. These are then "described" with `summarize_row_groups() %>%`, which creates for every split a -"content" table containing 1 row (the 1 in `cont: 1 x 6`), which +"content" table containing 1 row (the 1 in `cont: 1 x 6`), which when rendered takes the place of `LabelRow`. @@ -265,7 +279,7 @@ row_paths_summary(pruned) ``` Note in the latter we see content rows as those with paths following -`@content`, e.g., `ASIAN, @content, ASIAN`. The first of these at +`@content`, e.g., `ASIAN, @content, ASIAN`. The first of these at a given path (i.e., `, @content, <>` are the rows which will be used by the scoring functions which begin with `cont_`. @@ -490,7 +504,7 @@ We need the F and M percents, only for Arm C (i.e. columns 5 and 6), differenced. We will sort _**the strata within each ethnicity**_ by the percent -difference in counts between males and females in arm C. +difference in counts between males and females in arm C. Note: this is not statistically meaningful at all, and is in fact a terrible idea because it reorders the strata seemingly (but not) at diff --git a/vignettes/subsetting_tables.Rmd b/vignettes/subsetting_tables.Rmd index d79e44af3..07656eb03 100644 --- a/vignettes/subsetting_tables.Rmd +++ b/vignettes/subsetting_tables.Rmd @@ -7,10 +7,23 @@ vignette: > %\VignetteIndexEntry{Subsetting and Manipulating Table Contents} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") @@ -177,9 +190,9 @@ tbl # {1}, {2}, and {3} are present tbl[10, 2] # only {1} which was previously {2} ``` -Similar to what we have used to keep top left information, we can specify to -keep more information from the original table. As a standard the foot notes are -always present if the titles are kept. +Similar to what we have used to keep top left information, we can specify to +keep more information from the original table. As a standard the foot notes are +always present if the titles are kept. ```{r} tbl[1:3, 2:3, keep_titles = TRUE] tbl[1:3, 2:3, keep_titles = FALSE, keep_footers = TRUE] diff --git a/vignettes/tabulation_concepts.Rmd b/vignettes/tabulation_concepts.Rmd index 9a21172b2..af9270bb0 100644 --- a/vignettes/tabulation_concepts.Rmd +++ b/vignettes/tabulation_concepts.Rmd @@ -11,6 +11,20 @@ editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` diff --git a/vignettes/tabulation_dplyr.Rmd b/vignettes/tabulation_dplyr.Rmd index 29ab0f871..1ddd13ff0 100644 --- a/vignettes/tabulation_dplyr.Rmd +++ b/vignettes/tabulation_dplyr.Rmd @@ -7,11 +7,23 @@ vignette: > %\VignetteIndexEntry{Comparison with dplyr Tabulation} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- - +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` ```{r, echo=FALSE} knitr::opts_chunk$set(comment = "#") @@ -120,7 +132,7 @@ tbl <- build_table(lyt, df) tbl ``` -As mentioned in the introduction to this vignette, please ignore the difference in arranging and formatting the data: it's possible to condense the `rtable` more and it is possible to make the `tibble` look more like the reference table using the `gt` R package. +As mentioned in the introduction to this vignette, please ignore the difference in arranging and formatting the data: it's possible to condense the `rtable` more and it is possible to make the `tibble` look more like the reference table using the `gt` R package. In terms of tabulation for this example there was arguably not much added by `rtables` over `dplyr`. diff --git a/vignettes/title_footer.Rmd b/vignettes/title_footer.Rmd index a7680afbd..b6a1d5f9b 100644 --- a/vignettes/title_footer.Rmd +++ b/vignettes/title_footer.Rmd @@ -7,11 +7,25 @@ vignette: > %\VignetteIndexEntry{Titles, Footers, and Referential Footnotes} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` + ```{r, echo=FALSE, output="hide"} knitr::opts_chunk$set(comment = "#") suppressPackageStartupMessages(library(rtables)) From 18d1c74676eb3aa7a104834075b01e3bf559413b Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 03:56:55 +0000 Subject: [PATCH 11/18] [skip style] [skip vbump] Restyle files --- tests/testthat/setup-fakedata.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/setup-fakedata.R b/tests/testthat/setup-fakedata.R index 023dd0159..e21981752 100644 --- a/tests/testthat/setup-fakedata.R +++ b/tests/testthat/setup-fakedata.R @@ -183,11 +183,11 @@ tt_for_wrap <- tt_to_test_wrapping() tt_to_test_newline_chars <- function() { set.seed(1) - DM_trick <- DM - DM_trick$ARM = "ARM \n\nA\n" - DM_trick$ARM2 = sample(c("TWO\nwords\n ", "A wo\n\nrd\n\n"), - replace = TRUE, nrow(DM) - ) # last \n is eaten up if no empty space + DM_trick <- DM + DM_trick$ARM <- "ARM \n\nA\n" + DM_trick$ARM2 <- sample(c("TWO\nwords\n ", "A wo\n\nrd\n\n"), + replace = TRUE, nrow(DM) + ) # last \n is eaten up if no empty space levels(DM_trick$SEX)[3] <- "U\nN\nD\n" tbl <- basic_table() %>% split_rows_by("SEX", From 84055168ebb274d19e5e521e8512c1ee4b32f926 Mon Sep 17 00:00:00 2001 From: Joe Zhu Date: Fri, 6 Sep 2024 11:59:03 +0800 Subject: [PATCH 12/18] Update tests/testthat/test-as_html.R Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Signed-off-by: Joe Zhu --- tests/testthat/test-as_html.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-as_html.R b/tests/testthat/test-as_html.R index 0d9d599ec..71beeb2b9 100644 --- a/tests/testthat/test-as_html.R +++ b/tests/testthat/test-as_html.R @@ -1,8 +1,8 @@ context("Exporting to HTML") test_that("as_html smoke test", { - require(xml2, quietly = TRUE) skip_if_not_installed("xml2") + require(xml2, quietly = TRUE) tmpf <- tempfile(fileext = ".html") From 14f8cdbb0410f77adb65bbef46ac45a137d797c6 Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Fri, 6 Sep 2024 13:06:03 +0800 Subject: [PATCH 13/18] updat etst --- tests/testthat/test-as_html.R | 1 + tests/testthat/test-exporters.R | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/tests/testthat/test-as_html.R b/tests/testthat/test-as_html.R index 71beeb2b9..8f313495b 100644 --- a/tests/testthat/test-as_html.R +++ b/tests/testthat/test-as_html.R @@ -15,6 +15,7 @@ test_that("as_html smoke test", { }) test_that("as_html Viewer with newline test", { + skip_if_not_installed("xml2") tmpf <- tempfile(fileext = ".html") colfuns <- list( diff --git a/tests/testthat/test-exporters.R b/tests/testthat/test-exporters.R index 92c6d1046..9654a76d1 100644 --- a/tests/testthat/test-exporters.R +++ b/tests/testthat/test-exporters.R @@ -235,6 +235,9 @@ test_that("export_as_rtf works", { # Flextable and docx support --------------------------------------------------- test_that("Can create flextable object that works with different styles", { + skip_if_not_installed("flextable") + require("flextable", quietly = TRUE) + analysisfun <- function(x, ...) { in_rows( row1 = 5, @@ -318,6 +321,9 @@ test_that("Can create flextable object that works with different styles", { }) test_that("export_as_doc works thanks to tt_to_flextable", { + skip_if_not_installed("flextable") + require("flextable", quietly = TRUE) + lyt <- make_big_lyt() tbl <- build_table(lyt, rawdat) top_left(tbl) <- "Ethnicity" From 96ab0e569563fdb111f8871926facf3deaace488 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 05:09:01 +0000 Subject: [PATCH 14/18] [skip style] [skip vbump] Restyle files --- tests/testthat/test-exporters.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-exporters.R b/tests/testthat/test-exporters.R index 9654a76d1..33013e149 100644 --- a/tests/testthat/test-exporters.R +++ b/tests/testthat/test-exporters.R @@ -237,7 +237,7 @@ test_that("export_as_rtf works", { test_that("Can create flextable object that works with different styles", { skip_if_not_installed("flextable") require("flextable", quietly = TRUE) - + analysisfun <- function(x, ...) { in_rows( row1 = 5, @@ -323,7 +323,7 @@ test_that("Can create flextable object that works with different styles", { test_that("export_as_doc works thanks to tt_to_flextable", { skip_if_not_installed("flextable") require("flextable", quietly = TRUE) - + lyt <- make_big_lyt() tbl <- build_table(lyt, rawdat) top_left(tbl) <- "Ethnicity" From fa2fddbbff8ab2465cf972aca1168d1ea26c5994 Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Fri, 6 Sep 2024 13:18:41 +0800 Subject: [PATCH 15/18] update doc --- R/tree_accessors.R | 5 +++++ man/int_methods.Rd | 5 +++++ vignettes/split_functions.Rmd | 25 +++++++++++++++++++------ vignettes/subsetting_tables.Rmd | 2 +- vignettes/tabulation_dplyr.Rmd | 2 +- vignettes/title_footer.Rmd | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/R/tree_accessors.R b/R/tree_accessors.R index 48c75671c..462feb3d9 100644 --- a/R/tree_accessors.R +++ b/R/tree_accessors.R @@ -1614,6 +1614,11 @@ setMethod( ) #' @examples +#' lyt <- basic_table() %>% +#' split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) %>% +#' analyze("AGE") +#' +#' tbl <- build_table(lyt, DM) #' indent_mod(tbl) #' indent_mod(tbl) <- 1L #' tbl diff --git a/man/int_methods.Rd b/man/int_methods.Rd index 16ea11304..1cb0ce878 100644 --- a/man/int_methods.Rd +++ b/man/int_methods.Rd @@ -1290,6 +1290,11 @@ lyt <- basic_table() \%>\% tbl <- build_table(lyt, iris2) \dontshow{\}) # examplesIf} +lyt <- basic_table() \%>\% + split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) \%>\% + analyze("AGE") + +tbl <- build_table(lyt, DM) indent_mod(tbl) indent_mod(tbl) <- 1L tbl diff --git a/vignettes/split_functions.Rmd b/vignettes/split_functions.Rmd index bcfe346b5..613b4a888 100644 --- a/vignettes/split_functions.Rmd +++ b/vignettes/split_functions.Rmd @@ -7,10 +7,23 @@ vignette: > %\VignetteIndexEntry{Controlling Splitting Behavior} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- +```{r, include = FALSE} +suggested_dependent_pkgs <- c("dplyr", "tibble") +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = all(vapply( + suggested_dependent_pkgs, + requireNamespace, + logical(1), + quietly = TRUE + )) +) +``` # Controlling Facet Levels @@ -227,7 +240,7 @@ To add more arbitrary combinations, we use `add_combo_levels`. levels to the faceting structure of our table. We do this by defining a *combination data.frame* which describes the -levels we want to add. A combination `data.frame` has the +levels we want to add. A combination `data.frame` has the following columns and one row for each combination to add: - `valname` - string indicating the name of the value, which will appear @@ -280,7 +293,7 @@ as the combination of 3 steps: representing individual facets. 3. postprocessing - operations on the facets - e.g., combining them, removing them, etc. - + The `make_split_fun()` function allows us to specify custom behaviors for each of these steps independently when defining custom splitting behavior via the `pre`, `core_split`, and `post` arguments, which @@ -299,8 +312,8 @@ The pre-processing component is useful for things such as manipulating factor levels, e.g., to trim unobserved ones or to reorder levels based on observed counts, etc. -For a more detailed discussion on what custom split functions do, and an -example of a custom split function not implemented via `make_split_fun()`, +For a more detailed discussion on what custom split functions do, and an +example of a custom split function not implemented via `make_split_fun()`, see `?custom_split_funs`. ## An Example Custom Split Function @@ -458,7 +471,7 @@ either functions or function factories: - Pre-processing "behavior blocks" - `drop_facet_levels` - drop unobserved levels in the variable being split - + - Post-processing "behavior blocks" - `trim_levels_in_facets` - provides `trim_levels_in_group` behavior - `add_overall_facet` - add a combination facet for the full data diff --git a/vignettes/subsetting_tables.Rmd b/vignettes/subsetting_tables.Rmd index 07656eb03..599e113e4 100644 --- a/vignettes/subsetting_tables.Rmd +++ b/vignettes/subsetting_tables.Rmd @@ -12,7 +12,7 @@ editor_options: --- ```{r, include = FALSE} -suggested_dependent_pkgs <- c("dplyr") +suggested_dependent_pkgs <- c("dplyr", "tibble") knitr::opts_chunk$set( collapse = TRUE, comment = "#>", diff --git a/vignettes/tabulation_dplyr.Rmd b/vignettes/tabulation_dplyr.Rmd index 1ddd13ff0..be65fe4b9 100644 --- a/vignettes/tabulation_dplyr.Rmd +++ b/vignettes/tabulation_dplyr.Rmd @@ -12,7 +12,7 @@ editor_options: --- ```{r, include = FALSE} -suggested_dependent_pkgs <- c("dplyr") +suggested_dependent_pkgs <- c("dplyr", "tibble") knitr::opts_chunk$set( collapse = TRUE, comment = "#>", diff --git a/vignettes/title_footer.Rmd b/vignettes/title_footer.Rmd index b6a1d5f9b..83b5cef20 100644 --- a/vignettes/title_footer.Rmd +++ b/vignettes/title_footer.Rmd @@ -13,7 +13,7 @@ editor_options: ```{r, include = FALSE} -suggested_dependent_pkgs <- c("dplyr") +suggested_dependent_pkgs <- c("dplyr", "tibble") knitr::opts_chunk$set( collapse = TRUE, comment = "#>", From 03ab39f73cb89eac6ce3223982cbd4c0d7dcae0a Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Fri, 6 Sep 2024 13:31:31 +0800 Subject: [PATCH 16/18] update doc --- R/tt_export.R | 4 ++++ man/tt_to_flextable.Rd | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/tt_export.R b/R/tt_export.R index a98b09af2..bdef61698 100644 --- a/R/tt_export.R +++ b/R/tt_export.R @@ -808,6 +808,10 @@ margins_landscape <- function() { #' analyze("AGE", afun = analysisfun) #' #' tbl <- build_table(lyt, ex_adsl) +#' +#' @examplesIf require(flextable) +#' # example code +#' #' # rtables style #' tt_to_flextable(tbl, theme = NULL) #' diff --git a/man/tt_to_flextable.Rd b/man/tt_to_flextable.Rd index d35233314..a662e86e3 100644 --- a/man/tt_to_flextable.Rd +++ b/man/tt_to_flextable.Rd @@ -139,11 +139,15 @@ lyt <- basic_table( analyze("AGE", afun = analysisfun) tbl <- build_table(lyt, ex_adsl) + +\dontshow{if (require(flextable)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +# example code + # rtables style tt_to_flextable(tbl, theme = NULL) tt_to_flextable(tbl, theme = theme_docx_default(font_size = 6)) - +\dontshow{\}) # examplesIf} # Custom theme special_bold <- list( "header" = list("i" = 1, "j" = c(1, 3)), From 2b13635359e607808b6920c66ec5ddc689806dd2 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 05:35:00 +0000 Subject: [PATCH 17/18] [skip style] [skip vbump] Restyle files --- R/tt_export.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tt_export.R b/R/tt_export.R index bdef61698..a1db86f7a 100644 --- a/R/tt_export.R +++ b/R/tt_export.R @@ -808,10 +808,10 @@ margins_landscape <- function() { #' analyze("AGE", afun = analysisfun) #' #' tbl <- build_table(lyt, ex_adsl) -#' +#' #' @examplesIf require(flextable) #' # example code -#' +#' #' # rtables style #' tt_to_flextable(tbl, theme = NULL) #' From 5a2bc4e1005b5409e6bd221bfcb18cc372938683 Mon Sep 17 00:00:00 2001 From: shajoezhu Date: Fri, 6 Sep 2024 14:23:00 +0800 Subject: [PATCH 18/18] update doc --- R/tt_export.R | 9 +++++---- man/export_as_docx.Rd | 6 +++--- man/tt_to_flextable.Rd | 5 ++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/R/tt_export.R b/R/tt_export.R index bdef61698..05ee26a84 100644 --- a/R/tt_export.R +++ b/R/tt_export.R @@ -596,7 +596,8 @@ formatters::export_as_pdf #' #' @seealso [tt_to_flextable()] #' -#' @examples +#' @examplesIf require(flextable) +#' library(flextable) #' lyt <- basic_table() %>% #' split_cols_by("ARM") %>% #' analyze(c("AGE", "BMRKR2", "COUNTRY")) @@ -604,13 +605,11 @@ formatters::export_as_pdf #' tbl <- build_table(lyt, ex_adsl) #' #' # See how section_properties_portrait function is built for custom -#' \dontrun{ #' tf <- tempfile(fileext = ".docx") #' export_as_docx(tbl, #' file = tf, #' section_properties = section_properties_default(orientation = "landscape") #' ) -#' } #' #' @export export_as_docx <- function(tt, @@ -810,6 +809,7 @@ margins_landscape <- function() { #' tbl <- build_table(lyt, ex_adsl) #' #' @examplesIf require(flextable) +#' library(flextable) #' # example code #' #' # rtables style @@ -1045,7 +1045,8 @@ tt_to_flextable <- function(tt, #' #' @seealso [export_as_docx()] #' -#' @examples +#' @examplesIf require(flextable) +#' library(flextable) #' # Custom theme #' special_bold <- list( #' "header" = list("i" = 1, "j" = c(1, 3)), diff --git a/man/export_as_docx.Rd b/man/export_as_docx.Rd index ee48229e2..01ed3ddc3 100644 --- a/man/export_as_docx.Rd +++ b/man/export_as_docx.Rd @@ -78,6 +78,8 @@ we suggest that you use \code{\link[=tt_to_flextable]{tt_to_flextable()}} prior \code{footer_as_text} parameters must be re-specified if the table is changed first using \code{\link[=tt_to_flextable]{tt_to_flextable()}}. } \examples{ +\dontshow{if (require(flextable)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +library(flextable) lyt <- basic_table() \%>\% split_cols_by("ARM") \%>\% analyze(c("AGE", "BMRKR2", "COUNTRY")) @@ -85,14 +87,12 @@ lyt <- basic_table() \%>\% tbl <- build_table(lyt, ex_adsl) # See how section_properties_portrait function is built for custom -\dontrun{ tf <- tempfile(fileext = ".docx") export_as_docx(tbl, file = tf, section_properties = section_properties_default(orientation = "landscape") ) -} - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=tt_to_flextable]{tt_to_flextable()}} diff --git a/man/tt_to_flextable.Rd b/man/tt_to_flextable.Rd index a662e86e3..05fa2f4d9 100644 --- a/man/tt_to_flextable.Rd +++ b/man/tt_to_flextable.Rd @@ -141,6 +141,7 @@ lyt <- basic_table( tbl <- build_table(lyt, ex_adsl) \dontshow{if (require(flextable)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +library(flextable) # example code # rtables style @@ -148,6 +149,8 @@ tt_to_flextable(tbl, theme = NULL) tt_to_flextable(tbl, theme = theme_docx_default(font_size = 6)) \dontshow{\}) # examplesIf} +\dontshow{if (require(flextable)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +library(flextable) # Custom theme special_bold <- list( "header" = list("i" = 1, "j" = c(1, 3)), @@ -164,7 +167,7 @@ tt_to_flextable(tbl, border = flextable::fp_border_default(color = "pink", width = 2), theme = custom_theme ) - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=export_as_docx]{export_as_docx()}}