diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 67142d48c0..9c39ccb21b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,6 @@ repos: - id: roxygenize additional_dependencies: - insightsengineering/formatters - - magrittr - methods - checkmate - htmltools diff --git a/DESCRIPTION b/DESCRIPTION index dfa619551b..be1f05b68b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,6 +16,7 @@ Authors@R: c( comment = c(ORCID = "0009-0005-2083-1105")), person("Joe", "Zhu", , "joe.zhu@roche.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7566-2787")), + person("David", "Munoz Tord", , "david.munoztord@mailbox.org", role = "ctb"), person("F. Hoffmann-La Roche AG", role = c("cph", "fnd")) ) Description: Reporting tables often have structure that goes beyond simple @@ -34,7 +35,6 @@ URL: https://github.com/insightsengineering/rtables, BugReports: https://github.com/insightsengineering/rtables/issues Depends: formatters (>= 0.5.12), - magrittr (>= 2.0.3), methods, R (>= 4.1) Imports: @@ -61,7 +61,7 @@ VignetteBuilder: knitr, rmarkdown Config/Needs/verdepcheck: insightsengineering/formatters, - tidyverse/magrittr, mllg/checkmate, rstudio/htmltools, + mllg/checkmate, rstudio/htmltools, gagolews/stringi, tidymodels/broom, cran/car, tidyverse/dplyr, davidgohel/flextable, yihui/knitr, r-lib/lifecycle, davidgohel/officer, Merck/r2rtf, rstudio/rmarkdown, therneau/survival, diff --git a/NAMESPACE b/NAMESPACE index 70c51901fc..91942d412d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -318,15 +318,9 @@ import(methods) importFrom(formatters,do_forced_paginate) importFrom(formatters,export_as_pdf) importFrom(formatters,export_as_txt) -importFrom(htmltools,tagList) importFrom(htmltools,tags) -importFrom(lifecycle,deprecated) -importFrom(magrittr,"%>%") -importFrom(stats,binom.test) importFrom(stats,na.omit) -importFrom(stats,prop.test) importFrom(stats,quantile) -importFrom(stats,relevel) importFrom(stats,setNames) importFrom(tools,file_ext) importFrom(utils,browseURL) diff --git a/R/Viewer.R b/R/Viewer.R index fb0b93d6f9..accecde85b 100644 --- a/R/Viewer.R +++ b/R/Viewer.R @@ -20,8 +20,8 @@ NULL #' #' df <- cbind(iris, sl5 = sl5) #' -#' lyt <- basic_table() %>% -#' split_cols_by("sl5") %>% +#' lyt <- basic_table() |> +#' split_cols_by("sl5") |> #' analyze("Sepal.Length") #' #' tbl <- build_table(lyt, df) diff --git a/R/colby_constructors.R b/R/colby_constructors.R index 9a0161d09b..d54c927bf6 100644 --- a/R/colby_constructors.R +++ b/R/colby_constructors.R @@ -289,8 +289,8 @@ setMethod( #' @inheritSection custom_split_funs Custom Splitting Function Details #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze(c("AGE", "BMRKR2")) #' #' tbl <- build_table(lyt, ex_adsl) @@ -298,11 +298,11 @@ setMethod( #' #' # Let's look at the splits in more detail #' -#' lyt1 <- basic_table() %>% split_cols_by("ARM") +#' lyt1 <- basic_table() |> split_cols_by("ARM") #' lyt1 #' #' # add an analysis (summary) -#' lyt2 <- lyt1 %>% +#' lyt2 <- lyt1 |> #' analyze(c("AGE", "COUNTRY"), #' afun = list_wrap_x(summary), #' format = "xx.xx" @@ -316,13 +316,13 @@ setMethod( #' # By default sequentially adding layouts results in nesting #' library(dplyr) #' -#' DM_MF <- DM %>% -#' filter(SEX %in% c("M", "F")) %>% +#' DM_MF <- DM |> +#' filter(SEX %in% c("M", "F")) |> #' mutate(SEX = droplevels(SEX)) #' -#' lyt3 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX") %>% +#' lyt3 <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX") |> #' analyze(c("AGE", "COUNTRY"), #' afun = list_wrap_x(summary), #' format = "xx.xx" @@ -333,21 +333,21 @@ setMethod( #' tbl3 #' #' # nested=TRUE vs not -#' lyt4 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX", split_fun = drop_split_levels) %>% -#' split_rows_by("RACE", split_fun = drop_split_levels) %>% +#' lyt4 <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX", split_fun = drop_split_levels) |> +#' split_rows_by("RACE", split_fun = drop_split_levels) |> #' analyze("AGE") #' lyt4 #' #' tbl4 <- build_table(lyt4, DM) #' tbl4 #' -#' lyt5 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX", split_fun = drop_split_levels) %>% -#' analyze("AGE") %>% -#' split_rows_by("RACE", nested = FALSE, split_fun = drop_split_levels) %>% +#' lyt5 <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX", split_fun = drop_split_levels) |> +#' analyze("AGE") |> +#' split_rows_by("RACE", nested = FALSE, split_fun = drop_split_levels) |> #' analyze("AGE") #' lyt5 #' @@ -444,31 +444,31 @@ setMethod( #' informative, but that will change in the future. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("RACE", split_fun = drop_split_levels) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("RACE", split_fun = drop_split_levels) |> #' analyze("AGE", mean, var_labels = "Age", format = "xx.xx") #' #' tbl <- build_table(lyt, DM) #' tbl #' -#' lyt2 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("RACE") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("RACE") |> #' analyze("AGE", mean, var_labels = "Age", format = "xx.xx") #' #' tbl2 <- build_table(lyt2, DM) #' tbl2 #' -#' lyt3 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX") %>% -#' summarize_row_groups(label_fstr = "Overall (N)") %>% +#' lyt3 <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX") |> +#' summarize_row_groups(label_fstr = "Overall (N)") |> #' split_rows_by("RACE", #' split_label = "Ethnicity", labels_var = "ethn_lab", #' split_fun = drop_split_levels -#' ) %>% -#' summarize_row_groups("RACE", label_fstr = "%s (n)") %>% +#' ) |> +#' summarize_row_groups("RACE", label_fstr = "%s (n)") |> #' analyze("AGE", var_labels = "Age", afun = mean, format = "xx.xx") #' #' lyt3 @@ -476,8 +476,8 @@ setMethod( #' @examplesIf require(dplyr) #' library(dplyr) #' -#' DM2 <- DM %>% -#' filter(SEX %in% c("M", "F")) %>% +#' DM2 <- DM |> +#' filter(SEX %in% c("M", "F")) |> #' mutate( #' SEX = droplevels(SEX), #' gender_lab = c( @@ -555,7 +555,7 @@ split_rows_by <- function(lyt, #' @examplesIf require(dplyr) #' library(dplyr) #' -#' ANL <- DM %>% mutate(value = rnorm(n()), pctdiff = runif(n())) +#' ANL <- DM |> mutate(value = rnorm(n()), pctdiff = runif(n())) #' #' ## toy example where we take the mean of the first variable and the #' ## count of >.5 for the second. @@ -564,14 +564,14 @@ split_rows_by <- function(lyt, #' function(x) in_rows("# x > 5" = sum(x > .5), .formats = "xx") #' ) #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by_multivar(c("value", "pctdiff")) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by_multivar(c("value", "pctdiff")) |> #' split_rows_by("RACE", #' split_label = "ethnicity", #' split_fun = drop_split_levels -#' ) %>% -#' summarize_row_groups() %>% +#' ) |> +#' summarize_row_groups() |> #' analyze_colvars(afun = colfuns) #' lyt #' @@ -616,10 +616,10 @@ split_cols_by_multivar <- function(lyt, #' split on a column basis. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by_multivar(c("SEX", "STRATA1")) %>% -#' summarize_row_groups() %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by_multivar(c("SEX", "STRATA1")) |> +#' summarize_row_groups() |> #' analyze(c("AGE", "SEX")) #' #' tbl <- build_table(lyt, DM) @@ -671,28 +671,28 @@ split_rows_by_multivar <- function(lyt, #' library(dplyr) #' #' # split_cols_by_cuts -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' split_cols_by_cuts("AGE", #' split_label = "Age", #' cuts = c(0, 25, 35, 1000), #' cutlabels = c("young", "medium", "old") -#' ) %>% -#' analyze(c("BMRKR2", "STRATA2")) %>% +#' ) |> +#' analyze(c("BMRKR2", "STRATA2")) |> #' append_topleft("counts") #' #' tbl <- build_table(lyt, ex_adsl) #' tbl #' #' # split_rows_by_cuts -#' lyt2 <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("ARM") |> #' split_rows_by_cuts("AGE", #' split_label = "Age", #' cuts = c(0, 25, 35, 1000), #' cutlabels = c("young", "medium", "old") -#' ) %>% -#' analyze(c("BMRKR2", "STRATA2")) %>% +#' ) |> +#' analyze(c("BMRKR2", "STRATA2")) |> #' append_topleft("counts") #' #' @@ -701,20 +701,20 @@ split_rows_by_multivar <- function(lyt, #' #' # split_cols_by_quartiles #' -#' lyt3 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by_quartiles("AGE", split_label = "Age") %>% -#' analyze(c("BMRKR2", "STRATA2")) %>% +#' lyt3 <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by_quartiles("AGE", split_label = "Age") |> +#' analyze(c("BMRKR2", "STRATA2")) |> #' append_topleft("counts") #' #' tbl3 <- build_table(lyt3, ex_adsl) #' tbl3 #' #' # split_rows_by_quartiles -#' lyt4 <- basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM") %>% -#' split_rows_by_quartiles("AGE", split_label = "Age") %>% -#' analyze("BMRKR2") %>% +#' lyt4 <- basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM") |> +#' split_rows_by_quartiles("AGE", split_label = "Age") |> +#' analyze("BMRKR2") |> #' append_topleft(c("Age Quartiles", " Counts BMRKR2")) #' #' tbl4 <- build_table(lyt4, ex_adsl) @@ -732,17 +732,17 @@ split_rows_by_multivar <- function(lyt, #' cutpoints #' } #' -#' lyt5 <- basic_table() %>% -#' split_cols_by_cutfun("AGE", cutfun = cutfun) %>% +#' lyt5 <- basic_table() |> +#' split_cols_by_cutfun("AGE", cutfun = cutfun) |> #' analyze("SEX") #' #' tbl5 <- build_table(lyt5, ex_adsl) #' tbl5 #' #' # split_rows_by_cutfun -#' lyt6 <- basic_table() %>% -#' split_cols_by("SEX") %>% -#' split_rows_by_cutfun("AGE", cutfun = cutfun) %>% +#' lyt6 <- basic_table() |> +#' split_cols_by("SEX") |> +#' split_rows_by_cutfun("AGE", cutfun = cutfun) |> #' analyze("BMRKR2") #' #' tbl6 <- build_table(lyt6, ex_adsl) @@ -1163,16 +1163,16 @@ NULL #' the unmodified values provided by the tabulation framework. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") #' lyt #' #' tbl <- build_table(lyt, DM) #' tbl #' -#' lyt2 <- basic_table() %>% -#' split_cols_by("Species") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("Species") |> #' analyze(head(names(iris), -1), afun = function(x) { #' list( #' "mean / sd" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -1318,7 +1318,7 @@ get_acolvar_vars <- function(lyt) { #' @examplesIf require(dplyr) #' library(dplyr) #' -#' ANL <- DM %>% mutate(value = rnorm(n()), pctdiff = runif(n())) +#' ANL <- DM |> mutate(value = rnorm(n()), pctdiff = runif(n())) #' #' ## toy example where we take the mean of the first variable and the #' ## count of >.5 for the second. @@ -1327,30 +1327,30 @@ get_acolvar_vars <- function(lyt) { #' function(x) rcell(sum(x > .5), format = "xx") #' ) #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by_multivar(c("value", "pctdiff")) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by_multivar(c("value", "pctdiff")) |> #' split_rows_by("RACE", #' split_label = "ethnicity", #' split_fun = drop_split_levels -#' ) %>% -#' summarize_row_groups() %>% +#' ) |> +#' summarize_row_groups() |> #' analyze_colvars(afun = colfuns) #' lyt #' #' tbl <- build_table(lyt, ANL) #' tbl #' -#' lyt2 <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("ARM") |> #' split_cols_by_multivar(c("value", "pctdiff"), #' varlabels = c("Measurement", "Pct Diff") -#' ) %>% +#' ) |> #' split_rows_by("RACE", #' split_label = "ethnicity", #' split_fun = drop_split_levels -#' ) %>% -#' summarize_row_groups() %>% +#' ) |> +#' summarize_row_groups() |> #' analyze_colvars(afun = mean, format = "xx.xx") #' #' tbl2 <- build_table(lyt2, ANL) @@ -1426,9 +1426,9 @@ analyze_colvars <- function(lyt, #' @seealso [add_overall_level()] #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' add_overall_col("All Patients") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' add_overall_col("All Patients") |> #' analyze("AGE") #' lyt #' @@ -1708,10 +1708,10 @@ counts_wpcts <- function(x, .N_col) { #' @examples #' DM2 <- subset(DM, COUNTRY %in% c("USA", "CAN", "CHN")) #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("COUNTRY", split_fun = drop_split_levels) %>% -#' summarize_row_groups(label_fstr = "%s (n)") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("COUNTRY", split_fun = drop_split_levels) |> +#' summarize_row_groups(label_fstr = "%s (n)") |> #' analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") #' lyt #' @@ -1733,14 +1733,14 @@ counts_wpcts <- function(x, .N_col) { #' ) #' } #' -#' lyt2 <- basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("COUNTRY", split_fun = drop_split_levels) %>% +#' lyt2 <- basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM") |> +#' split_rows_by("COUNTRY", split_fun = drop_split_levels) |> #' summarize_row_groups("AGE", #' cfun = sfun, #' extra_args = list(trim = .2) -#' ) %>% -#' analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") %>% +#' ) |> +#' analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") |> #' append_topleft(c("Country", " Age")) #' #' tbl2 <- build_table(lyt2, DM2) @@ -1788,10 +1788,10 @@ summarize_row_groups <- function(lyt, #' @inherit split_cols_by return #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' add_colcounts() %>% -#' split_rows_by("RACE", split_fun = drop_split_levels) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' add_colcounts() |> +#' split_rows_by("RACE", split_fun = drop_split_levels) |> #' analyze("AGE", afun = function(x) list(min = min(x), max = max(x))) #' lyt #' @@ -1818,16 +1818,16 @@ add_colcounts <- function(lyt, format = "(N=xx)") { #' @inherit split_cols_by return #' #' @examples -#' lyt1 <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt1 <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze("AGE", afun = mean, format = "xx.xx") #' #' tbl1 <- build_table(lyt1, DM) #' tbl1 #' -#' lyt2 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' analyze("AGE", afun = sd, format = "xx.xx") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("ARM") |> +#' analyze("AGE", afun = sd, format = "xx.xx") |> #' add_existing_table(tbl1) #' #' tbl2 <- build_table(lyt2, DM) @@ -2008,9 +2008,9 @@ manual_cols <- function(..., .lst = list(...), ccount_format = NULL) { #' #' @export #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX") |> #' analyze("AGE") #' tbl <- build_table(lyt, ex_adsl) #' @@ -2160,7 +2160,7 @@ list_wrap_df <- function(f) { #' indentation on multiple lines. #' #' @examples -#' lyt <- basic_table() %>% +#' lyt <- basic_table() |> #' analyze("AGE", afun = mean) #' #' tbl <- build_table(lyt, DM) @@ -2174,8 +2174,8 @@ list_wrap_df <- function(f) { #' "test.R program, executed at", #' Sys.time() #' ) -#' ) %>% -#' split_cols_by("ARM") %>% +#' ) |> +#' split_cols_by("ARM") |> #' analyze("AGE", mean) #' #' tbl2 <- build_table(lyt2, DM) @@ -2184,7 +2184,7 @@ list_wrap_df <- function(f) { #' lyt3 <- basic_table( #' show_colcounts = TRUE, #' colcount_format = "xx. (xx.%)" -#' ) %>% +#' ) |> #' split_cols_by("ARM") #' #' @export @@ -2253,14 +2253,14 @@ basic_table <- function(title = "", #' @examplesIf require(dplyr) #' library(dplyr) #' -#' DM2 <- DM %>% mutate(RACE = factor(RACE), SEX = factor(SEX)) +#' DM2 <- DM |> mutate(RACE = factor(RACE), SEX = factor(SEX)) #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX") %>% -#' split_rows_by("RACE") %>% -#' append_topleft("Ethnicity") %>% -#' analyze("AGE") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX") |> +#' split_rows_by("RACE") |> +#' append_topleft("Ethnicity") |> +#' analyze("AGE") |> #' append_topleft(" Age") #' #' tbl <- build_table(lyt, DM2) diff --git a/R/custom_split_funs.R b/R/custom_split_funs.R index 2a0fe170be..984fadd60a 100644 --- a/R/custom_split_funs.R +++ b/R/custom_split_funs.R @@ -110,9 +110,9 @@ setGeneric( #' d1$SEX <- factor(d1$SEX) #' #' # This table uses the number of values in the SEX column to add the overall col or not -#' lyt <- basic_table() %>% -#' split_cols_by("ARM", split_fun = drop_split_levels) %>% -#' split_cols_by("SEX", split_fun = picky_splitter("SEX")) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM", split_fun = drop_split_levels) |> +#' split_cols_by("SEX", split_fun = picky_splitter("SEX")) |> #' analyze("AGE", show_labels = "visible") #' tbl <- build_table(lyt, d1) #' tbl @@ -253,12 +253,12 @@ NULL #' ret #' } #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' split_cols_by_multivar(c("USUBJID", "AESEQ", "BMRKR1"), #' varlabels = c("N", "E", "BMR1"), #' split_fun = uneven_splfun -#' ) %>% +#' ) |> #' analyze_colvars(list( #' USUBJID = function(x, ...) length(unique(x)), #' AESEQ = max, diff --git a/R/default_split_funs.R b/R/default_split_funs.R index 12482040a6..ca38911b65 100644 --- a/R/default_split_funs.R +++ b/R/default_split_funs.R @@ -54,10 +54,10 @@ NULL #' #' @examples #' # keep_split_levels keeps specified levels (reorder = TRUE by default) -#' lyt <- basic_table() %>% +#' lyt <- basic_table() |> #' split_rows_by("COUNTRY", #' split_fun = keep_split_levels(c("USA", "CAN", "BRA")) -#' ) %>% +#' ) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -105,13 +105,13 @@ keep_split_levels <- function(only, reorder = TRUE) { #' #' @examples #' # remove_split_levels removes specified split levels -#' lyt <- basic_table() %>% +#' lyt <- basic_table() |> #' split_rows_by("COUNTRY", #' split_fun = remove_split_levels(c( #' "USA", "CAN", #' "CHE", "BRA" #' )) -#' ) %>% +#' ) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -140,8 +140,8 @@ remove_split_levels <- function(excl) { #' #' @examples #' # drop_split_levels drops levels that are not present in the data -#' lyt <- basic_table() %>% -#' split_rows_by("SEX", split_fun = drop_split_levels) %>% +#' lyt <- basic_table() |> +#' split_rows_by("SEX", split_fun = drop_split_levels) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -173,8 +173,8 @@ drop_split_levels <- function(df, #' #' @examples #' # Removing "M" and "U" directly, then "UNDIFFERENTIATED" because not in data -#' lyt <- basic_table() %>% -#' split_rows_by("SEX", split_fun = drop_and_remove_levels(c("M", "U"))) %>% +#' lyt <- basic_table() |> +#' split_rows_by("SEX", split_fun = drop_and_remove_levels(c("M", "U"))) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -211,21 +211,21 @@ drop_and_remove_levels <- function(excl) { #' #' @examples #' # Reordering levels in split variable -#' lyt <- basic_table() %>% +#' lyt <- basic_table() |> #' split_rows_by( #' "SEX", #' split_fun = reorder_split_levels( #' neworder = c("U", "F"), #' newlabels = c(U = "Uu", `F` = "Female") #' ) -#' ) %>% +#' ) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) #' tbl #' #' # Reordering levels in split variable but keeping all the levels -#' lyt <- basic_table() %>% +#' lyt <- basic_table() |> #' split_rows_by( #' "SEX", #' split_fun = reorder_split_levels( @@ -233,7 +233,7 @@ drop_and_remove_levels <- function(excl) { #' newlabels = c("Uu", "Female"), #' drlevels = FALSE #' ) -#' ) %>% +#' ) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -322,9 +322,9 @@ reorder_split_levels <- function(neworder, #' col2 = factor(c("a", "b", "c"), levels = c("a", "b", "c", "x")) #' ) # N is removed if drop_outlevs = TRUE, x is removed always #' -#' tbl <- basic_table() %>% -#' split_rows_by("col1", split_fun = trim_levels_in_group("col2")) %>% -#' analyze("col2") %>% +#' tbl <- basic_table() |> +#' split_rows_by("col1", split_fun = trim_levels_in_group("col2")) |> +#' analyze("col2") |> #' build_table(dat) #' tbl #' @@ -416,21 +416,21 @@ trim_levels_in_group <- function(innervar, drop_outlevs = TRUE) { #' @seealso [custom_split_funs] and [split_funcs]. #' #' @examples -#' lyt <- basic_table() %>% +#' lyt <- basic_table() |> #' split_cols_by("ARM", split_fun = add_overall_level("All Patients", #' first = FALSE -#' )) %>% +#' )) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) #' tbl #' -#' lyt2 <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("ARM") |> #' split_rows_by("RACE", #' split_fun = add_overall_level("All Ethnicities") -#' ) %>% -#' summarize_row_groups(label_fstr = "%s (n)") %>% +#' ) |> +#' summarize_row_groups(label_fstr = "%s (n)") |> #' analyze("AGE") #' lyt2 #' @@ -483,14 +483,14 @@ select_all_levels <- new("AllLevelsSentinel") #' "A_C", "Arms A+C", c("A: Drug X", "C: Combination"), list() #' ) #' -#' lyt <- basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM", split_fun = add_combo_levels(combodf)) %>% +#' lyt <- basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM", split_fun = add_combo_levels(combodf)) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) #' tbl #' -#' lyt1 <- basic_table(show_colcounts = TRUE) %>% +#' lyt1 <- basic_table(show_colcounts = TRUE) |> #' split_cols_by("ARM", #' split_fun = add_combo_levels(combodf, #' keep_levels = c( @@ -498,7 +498,7 @@ select_all_levels <- new("AllLevelsSentinel") #' "A_C" #' ) #' ) -#' ) %>% +#' ) |> #' analyze("AGE") #' #' tbl1 <- build_table(lyt1, DM) @@ -506,19 +506,19 @@ select_all_levels <- new("AllLevelsSentinel") #' #' smallerDM <- droplevels(subset(DM, SEX %in% c("M", "F") & #' grepl("^(A|B)", ARM))) -#' lyt2 <- basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM", split_fun = add_combo_levels(combodf[1, ])) %>% +#' lyt2 <- basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM", split_fun = add_combo_levels(combodf[1, ])) |> #' split_cols_by("SEX", #' split_fun = add_overall_level("SEX_ALL", "All Genders") -#' ) %>% +#' ) |> #' analyze("AGE") #' -#' lyt3 <- basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM", split_fun = add_combo_levels(combodf)) %>% +#' lyt3 <- basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM", split_fun = add_combo_levels(combodf)) |> #' split_rows_by("SEX", #' split_fun = add_overall_level("SEX_ALL", "All Genders") -#' ) %>% -#' summarize_row_groups() %>% +#' ) |> +#' summarize_row_groups() |> #' analyze("AGE") #' #' tbl3 <- build_table(lyt3, smallerDM) @@ -607,9 +607,9 @@ add_combo_levels <- function(combosdf, #' stringsAsFactors = FALSE #' ) #' -#' lyt <- basic_table() %>% -#' split_rows_by("LBCAT") %>% -#' split_rows_by("PARAMCD", split_fun = trim_levels_to_map(map = map)) %>% +#' lyt <- basic_table() |> +#' split_rows_by("LBCAT") |> +#' split_rows_by("PARAMCD", split_fun = trim_levels_to_map(map = map)) |> #' analyze("ANRIND") #' tbl <- build_table(lyt, ex_adlb) #' diff --git a/R/indent.R b/R/indent.R index 8c1e60ccf8..826a2d494a 100644 --- a/R/indent.R +++ b/R/indent.R @@ -48,10 +48,10 @@ indent <- function(x, by = 1) { #' @return The same class as `tt`, with all indent modifiers set to zero. #' #' @examples -#' lyt1 <- basic_table() %>% -#' summarize_row_groups("STUDYID", label_fstr = "overall summary") %>% -#' split_rows_by("AEBODSYS", child_labels = "visible") %>% -#' summarize_row_groups("STUDYID", label_fstr = "subgroup summary") %>% +#' lyt1 <- basic_table() |> +#' summarize_row_groups("STUDYID", label_fstr = "overall summary") |> +#' split_rows_by("AEBODSYS", child_labels = "visible") |> +#' summarize_row_groups("STUDYID", label_fstr = "subgroup summary") |> #' analyze("AGE", indent_mod = -1L) #' #' tbl1 <- build_table(lyt1, ex_adae) diff --git a/R/make_split_fun.R b/R/make_split_fun.R index bf7812facd..ba1d744972 100644 --- a/R/make_split_fun.R +++ b/R/make_split_fun.R @@ -196,9 +196,9 @@ add_to_split_result <- function(splres, values, datasplit, labels, extras = NULL #' post = list(add_overall_facet("ALL", "All Arms")) #' ) #' -#' basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM", split_fun = mysplitfun) %>% -#' analyze("AGE") %>% +#' basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM", split_fun = mysplitfun) |> +#' analyze("AGE") |> #' build_table(subset(DM, ARM %in% c("B: Placebo", "C: Combination"))) #' #' ## post (and pre) arguments can take multiple functions, here @@ -219,9 +219,9 @@ add_to_split_result <- function(splres, values, datasplit, labels, extras = NULL #' reorder_facets #' ) #' ) -#' basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM", split_fun = mysplitfun2) %>% -#' analyze("AGE") %>% +#' basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM", split_fun = mysplitfun2) |> +#' analyze("AGE") |> #' build_table(subset(DM, ARM %in% c("B: Placebo", "C: Combination"))) #' #' very_stupid_core <- function(spl, df, vals, labels, .spl_context) { @@ -243,9 +243,9 @@ add_to_split_result <- function(splres, values, datasplit, labels, extras = NULL #' ## recall core split overriding is not supported in column space #' ## currently, but we can see it in action in row space #' -#' lyt_silly <- basic_table() %>% -#' split_rows_by("ARM", split_fun = nonsense_splfun) %>% -#' summarize_row_groups() %>% +#' lyt_silly <- basic_table() |> +#' split_rows_by("ARM", split_fun = nonsense_splfun) |> +#' summarize_row_groups() |> #' analyze("AGE") #' silly_table <- build_table(lyt_silly, DM) #' silly_table @@ -327,8 +327,8 @@ make_split_fun <- function(pre = list(), core_split = NULL, post = list()) { #' add_overall_facet("ALL", label = "All Arms") #' )) #' -#' lyt <- basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM", split_fun = mysplfun) %>% +#' lyt <- basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM", split_fun = mysplfun) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) diff --git a/R/package.R b/R/package.R index 8b79f426b1..cdf8a37a2e 100644 --- a/R/package.R +++ b/R/package.R @@ -1,10 +1,5 @@ #' @keywords internal -"_PACKAGE" - -#' @importFrom utils head head.matrix tail tail.matrix -#' @importFrom stats setNames na.omit prop.test binom.test relevel quantile -#' @importFrom htmltools tags tagList -#' @importFrom lifecycle deprecated -#' @importFrom magrittr %>% #' @import methods -NULL +#' @importFrom stats setNames na.omit quantile +#' @importFrom utils head head.matrix tail tail.matrix +"_PACKAGE" diff --git a/R/summary.R b/R/summary.R index 99f0b7e3da..f2521a269d 100644 --- a/R/summary.R +++ b/R/summary.R @@ -9,8 +9,8 @@ #' @seealso [cell_values()], [`fnotes_at_path<-`], [row_paths_summary()], [col_paths_summary()] #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze(c("SEX", "AGE")) #' #' tbl <- build_table(lyt, ex_adsl) @@ -44,11 +44,11 @@ col_paths <- function(x) { #' @return A data frame summarizing the row- or column-structure of `x`. #' #' @examplesIf require(dplyr) -#' ex_adsl_MF <- ex_adsl %>% dplyr::filter(SEX %in% c("M", "F")) +#' ex_adsl_MF <- ex_adsl |> dplyr::filter(SEX %in% c("M", "F")) #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX", split_fun = drop_split_levels) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX", split_fun = drop_split_levels) |> #' analyze(c("AGE", "BMRKR2")) #' #' tbl <- build_table(lyt, ex_adsl_MF) @@ -158,14 +158,14 @@ col_paths_summary <- function(x) { #' @examplesIf require(dplyr) #' library(dplyr) #' -#' iris2 <- iris %>% -#' group_by(Species) %>% -#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>% +#' iris2 <- iris |> +#' group_by(Species) |> +#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> #' ungroup() #' -#' lyt <- basic_table() %>% -#' split_cols_by("Species") %>% -#' split_cols_by("group") %>% +#' lyt <- basic_table() |> +#' split_cols_by("Species") |> +#' split_cols_by("group") |> #' analyze(c("Sepal.Length", "Petal.Width"), #' afun = list_wrap_x(summary), #' format = "xx.xx" @@ -237,14 +237,14 @@ setMethod( #' @examplesIf require(dplyr) #' library(dplyr) #' -#' iris2 <- iris %>% -#' group_by(Species) %>% -#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>% +#' iris2 <- iris |> +#' group_by(Species) |> +#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> #' ungroup() #' -#' lyt <- basic_table() %>% -#' split_cols_by("Species") %>% -#' split_cols_by("group") %>% +#' lyt <- basic_table() |> +#' split_cols_by("Species") |> +#' split_cols_by("group") |> #' analyze(c("Sepal.Length", "Petal.Width"), #' afun = list_wrap_x(summary), #' format = "xx.xx" diff --git a/R/tree_accessors.R b/R/tree_accessors.R index 0c234d4130..577bd8d4ff 100644 --- a/R/tree_accessors.R +++ b/R/tree_accessors.R @@ -32,8 +32,8 @@ setMethod( #' @param x (`TableTree` or `ElementaryTable`)\cr a table object. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze(c("SEX", "AGE")) #' #' tbl <- build_table(lyt, ex_adsl) @@ -1327,8 +1327,8 @@ setMethod("content_na_str<-", "Split", function(obj, value) { #' @seealso [table_shell()] and [table_shell_str()] for information on the table format structure. #' #' @examples -#' lyt <- basic_table() %>% -#' split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) %>% +#' lyt <- basic_table() |> +#' split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -1628,8 +1628,8 @@ setMethod( ) #' @examples -#' lyt <- basic_table() %>% -#' split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) %>% +#' lyt <- basic_table() |> +#' split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -2675,13 +2675,13 @@ ct_recursive_replace <- function(ctree, path, value, pos = 1) { #' @seealso [col_counts()] #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM", show_colcounts = TRUE) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM", show_colcounts = TRUE) |> #' split_cols_by("SEX", #' split_fun = keep_split_levels(c("F", "M")), #' show_colcounts = TRUE -#' ) %>% -#' split_cols_by("STRATA1", show_colcounts = TRUE) %>% +#' ) |> +#' split_cols_by("STRATA1", show_colcounts = TRUE) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, ex_adsl) @@ -3306,15 +3306,15 @@ vil_collapse <- function(x) { #' * The order these variable names appear within the return vector is undefined and should not be relied upon. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX") %>% -#' summarize_row_groups(label_fstr = "Overall (N)") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX") |> +#' summarize_row_groups(label_fstr = "Overall (N)") |> #' split_rows_by("RACE", #' split_label = "Ethnicity", labels_var = "ethn_lab", #' split_fun = drop_split_levels -#' ) %>% -#' summarize_row_groups("RACE", label_fstr = "%s (n)") %>% +#' ) |> +#' summarize_row_groups("RACE", label_fstr = "%s (n)") |> #' analyze("AGE", var_labels = "Age", afun = mean, format = "xx.xx") #' #' vars_in_layout(lyt) @@ -3833,8 +3833,8 @@ setMethod( #' #' @examples #' # How to add referencial footnotes after having created a table -#' lyt <- basic_table() %>% -#' split_rows_by("SEX", page_by = TRUE) %>% +#' lyt <- basic_table() |> +#' split_rows_by("SEX", page_by = TRUE) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -4122,9 +4122,9 @@ setMethod("trailing_section_div<-", "TableRow", function(obj, value) { #' ) #' fast_afun <- function(x) list("m" = rcell(mean(x), format = "xx."), "m/2" = max(x) / 2) #' -#' tbl <- basic_table() %>% -#' split_rows_by("cat", section_div = "~") %>% -#' analyze("value", afun = fast_afun, section_div = " ") %>% +#' tbl <- basic_table() |> +#' split_rows_by("cat", section_div = "~") |> +#' analyze("value", afun = fast_afun, section_div = " ") |> #' build_table(df) #' #' # Getter diff --git a/R/tt_afun_utils.R b/R/tt_afun_utils.R index 6cc3db0ddd..fb71b0ab94 100644 --- a/R/tt_afun_utils.R +++ b/R/tt_afun_utils.R @@ -156,8 +156,8 @@ non_ref_rcell <- function(x, is_ref, format = NULL, colspan = 1L, #' in_rows(.list = list(a = 1, b = 2, c = 3)) #' in_rows(1, 2, .list = list(3), .names = c("a", "b", "c")) #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze("AGE", afun = function(x) { #' in_rows( #' "Mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), diff --git a/R/tt_as_df.R b/R/tt_as_df.R index 2ce473b3d6..b7616aa0de 100644 --- a/R/tt_as_df.R +++ b/R/tt_as_df.R @@ -40,9 +40,9 @@ #' had identical names. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("STRATA1") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("STRATA1") |> #' analyze(c("AGE", "BMRKR2")) #' #' tbl <- build_table(lyt, ex_adsl) @@ -673,8 +673,8 @@ handle_rdf_row <- function(rdfrow, maxlen, add_tbl_name_split = FALSE) { #' by `path_fun`). #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze(c("AGE", "BMRKR2")) #' #' tbl <- build_table(lyt, ex_adsl) diff --git a/R/tt_compare_tables.R b/R/tt_compare_tables.R index ede424e4de..a885cb51d8 100644 --- a/R/tt_compare_tables.R +++ b/R/tt_compare_tables.R @@ -17,17 +17,17 @@ #' adsl$AGE[adsl$SEX == "UNDIFFERENTIATED"] <- 0 #' adsl$BMRKR1 <- 0 #' -#' tbl_to_prune <- basic_table() %>% -#' analyze("BMRKR1") %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX") %>% -#' summarize_row_groups() %>% -#' split_rows_by("STRATA1") %>% -#' summarize_row_groups() %>% -#' analyze("AGE") %>% +#' tbl_to_prune <- basic_table() |> +#' analyze("BMRKR1") |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX") |> +#' summarize_row_groups() |> +#' split_rows_by("STRATA1") |> +#' summarize_row_groups() |> +#' analyze("AGE") |> #' build_table(adsl) #' -#' tbl_to_prune %>% prune_table(all_zero_or_na) +#' tbl_to_prune |> prune_table(all_zero_or_na) #' #' @rdname trim_prune_funs #' @export @@ -42,7 +42,7 @@ all_zero_or_na <- function(tr) { #' @details `all_zero` returns `TRUE` for any non-`LabelRow` which contains only (non-missing) zero values. #' #' @examples -#' tbl_to_prune %>% prune_table(all_zero) +#' tbl_to_prune |> prune_table(all_zero) #' #' @rdname trim_prune_funs #' @export @@ -78,19 +78,19 @@ all_zero <- function(tr) { #' adsl <- ex_adsl #' levels(adsl$SEX) <- c(levels(ex_adsl$SEX), "OTHER") #' -#' tbl_to_trim <- basic_table() %>% -#' analyze("BMRKR1") %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX") %>% -#' summarize_row_groups() %>% -#' split_rows_by("STRATA1") %>% -#' summarize_row_groups() %>% -#' analyze("AGE") %>% +#' tbl_to_trim <- basic_table() |> +#' analyze("BMRKR1") |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX") |> +#' summarize_row_groups() |> +#' split_rows_by("STRATA1") |> +#' summarize_row_groups() |> +#' analyze("AGE") |> #' build_table(adsl) #' -#' tbl_to_trim %>% trim_rows() +#' tbl_to_trim |> trim_rows() #' -#' tbl_to_trim %>% trim_rows(all_zero) +#' tbl_to_trim |> trim_rows(all_zero) #' #' @export trim_rows <- function(tt, criteria = all_zero_or_na) { @@ -118,7 +118,7 @@ trim_rows <- function(tt, criteria = all_zero_or_na) { #' (e.g. because a factor variable was used in [split_rows_by()] but not all levels were present in the data). #' #' @examples -#' tbl_to_prune %>% prune_table(content_all_zeros_nas) +#' tbl_to_prune |> prune_table(content_all_zeros_nas) #' #' @rdname trim_prune_funs #' @export @@ -141,7 +141,7 @@ content_all_zeros_nas <- function(tt, criteria = all_zero_or_na) { #' children. #' #' @examples -#' tbl_to_prune %>% prune_table(prune_empty_level) +#' tbl_to_prune |> prune_table(prune_empty_level) #' #' @rdname trim_prune_funs #' @export @@ -161,7 +161,7 @@ prune_empty_level <- function(tt) { #' only in the case of all non-missing zero values. #' #' @examples -#' tbl_to_prune %>% prune_table(prune_zeros_only) +#' tbl_to_prune |> prune_table(prune_zeros_only) #' #' @rdname trim_prune_funs #' @export @@ -188,7 +188,7 @@ prune_zeros_only <- function(tt) { #' #' @examples #' min_prune <- low_obs_pruner(70, "sum") -#' tbl_to_prune %>% prune_table(min_prune) +#' tbl_to_prune |> prune_table(min_prune) #' #' @rdname trim_prune_funs #' @export @@ -228,16 +228,16 @@ low_obs_pruner <- function(min, type = c("sum", "mean")) { #' adsl <- ex_adsl #' levels(adsl$SEX) <- c(levels(ex_adsl$SEX), "OTHER") #' -#' tbl_to_prune <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX") %>% -#' summarize_row_groups() %>% -#' split_rows_by("STRATA1") %>% -#' summarize_row_groups() %>% -#' analyze("AGE") %>% +#' tbl_to_prune <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX") |> +#' summarize_row_groups() |> +#' split_rows_by("STRATA1") |> +#' summarize_row_groups() |> +#' analyze("AGE") |> #' build_table(adsl) #' -#' tbl_to_prune %>% prune_table() +#' tbl_to_prune |> prune_table() #' #' @export prune_table <- function(tt, diff --git a/R/tt_compatibility.R b/R/tt_compatibility.R index 29f6533cd5..4744b316ad 100644 --- a/R/tt_compatibility.R +++ b/R/tt_compatibility.R @@ -1057,8 +1057,8 @@ chk_compat_cinfos <- function(tt1, tt2) { #' #' @examples #' o <- options(warn = 0) -#' lyt <- basic_table() %>% -#' split_cols_by("Species") %>% +#' lyt <- basic_table() |> +#' split_cols_by("Species") |> #' analyze("Sepal.Length") #' #' tbl <- build_table(lyt, iris) @@ -1066,9 +1066,9 @@ chk_compat_cinfos <- function(tt1, tt2) { #' insert_rrow(tbl, rrow("Hello World")) #' insert_rrow(tbl, rrow("Hello World"), at = 2) #' -#' lyt2 <- basic_table() %>% -#' split_cols_by("Species") %>% -#' split_rows_by("Species") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("Species") |> +#' split_rows_by("Species") |> #' analyze("Sepal.Length") #' #' tbl2 <- build_table(lyt2, iris) diff --git a/R/tt_dotabulation.R b/R/tt_dotabulation.R index 6e479c1f20..5f66fde77f 100644 --- a/R/tt_dotabulation.R +++ b/R/tt_dotabulation.R @@ -1324,8 +1324,8 @@ recursive_applysplit <- function(df, #' declared in `lyt` to the data `df`. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("Species") %>% +#' lyt <- basic_table() |> +#' split_cols_by("Species") |> #' analyze("Sepal.Length", afun = function(x) { #' list( #' "mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -1338,8 +1338,8 @@ recursive_applysplit <- function(df, #' tbl #' #' # analyze multiple variables -#' lyt2 <- basic_table() %>% -#' split_cols_by("Species") %>% +#' lyt2 <- basic_table() |> +#' split_cols_by("Species") |> #' analyze(c("Sepal.Length", "Petal.Width"), afun = function(x) { #' list( #' "mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -1351,8 +1351,8 @@ recursive_applysplit <- function(df, #' tbl2 #' #' # an example more relevant for clinical trials with column counts -#' lyt3 <- basic_table(show_colcounts = TRUE) %>% -#' split_cols_by("ARM") %>% +#' lyt3 <- basic_table(show_colcounts = TRUE) |> +#' split_cols_by("ARM") |> #' analyze("AGE", afun = function(x) { #' setNames(as.list(fivenum(x)), c( #' "minimum", "lower-hinge", "median", diff --git a/R/tt_export.R b/R/tt_export.R index 379a5116e2..bfa17f7ca7 100644 --- a/R/tt_export.R +++ b/R/tt_export.R @@ -53,8 +53,8 @@ import_from_tsv <- function(file) { #' @importFrom formatters export_as_txt #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze(c("AGE", "BMRKR2", "COUNTRY")) #' #' tbl <- build_table(lyt, ex_adsl) @@ -74,8 +74,8 @@ formatters::export_as_txt #' @importFrom formatters export_as_pdf #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' analyze(c("AGE", "BMRKR2", "COUNTRY")) #' #' tbl <- build_table(lyt, ex_adsl) diff --git a/R/tt_paginate.R b/R/tt_paginate.R index 91eff310ea..bff733b5c1 100644 --- a/R/tt_paginate.R +++ b/R/tt_paginate.R @@ -730,8 +730,8 @@ setMethod( #' } #' } #' -#' lyt <- basic_table() %>% -#' split_cols_by(var = "ARM") %>% +#' lyt <- basic_table() |> +#' split_cols_by(var = "ARM") |> #' analyze(c("AGE", "SEX", "BEP01FL", "BMRKR1", "BMRKR2", "COUNTRY"), afun = s_summary) #' #' tbl <- build_table(lyt, ex_adsl) diff --git a/R/tt_pos_and_access.R b/R/tt_pos_and_access.R index f79a45eb36..89ec904de4 100644 --- a/R/tt_pos_and_access.R +++ b/R/tt_pos_and_access.R @@ -130,8 +130,8 @@ col_fnotes_at_path <- function(ctree, path, fnotes) { #' @seealso [DataRow()], [rrow()] #' #' @examples -#' lyt <- basic_table() %>% -#' split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) %>% +#' lyt <- basic_table() |> +#' split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -239,8 +239,8 @@ setMethod( #' determining the full paths to content rows. #' #' @examples -#' lyt <- basic_table() %>% -#' split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) %>% +#' lyt <- basic_table() |> +#' split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, DM) @@ -534,13 +534,13 @@ tt_normalize_row_path <- function(obj, #' #' @examples #' # Accessing sub table. -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX") %>% -#' split_rows_by("BMRKR2") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX") |> +#' split_rows_by("BMRKR2") |> #' analyze("AGE") #' -#' tbl <- build_table(lyt, ex_adsl) %>% prune_table() +#' tbl <- build_table(lyt, ex_adsl) |> prune_table() #' sub_tbl <- tt_at_path(tbl, path = c("SEX", "F", "BMRKR2")) #' #' # Removing sub table. @@ -549,12 +549,12 @@ tt_normalize_row_path <- function(obj, #' tbl2 #' #' # Setting sub table. -#' lyt3 <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX") %>% +#' lyt3 <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX") |> #' analyze("BMRKR2") #' -#' tbl3 <- build_table(lyt3, ex_adsl) %>% prune_table() +#' tbl3 <- build_table(lyt3, ex_adsl) |> prune_table() #' #' tt_at_path(tbl3, path = c("SEX", "F", "BMRKR2")) <- sub_tbl #' tbl3 @@ -648,9 +648,9 @@ setMethod( #' subtitles = c("Sub", "titles"), #' prov_footer = "prov footer", #' main_footer = "main footer" -#' ) %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX") %>% +#' ) |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX") |> #' analyze(c("AGE")) #' #' tbl <- build_table(lyt, DM) @@ -860,9 +860,9 @@ setMethod( #' subtitles = c("Sub", "titles"), #' prov_footer = "prov footer", #' main_footer = "main footer" -#' ) %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX") %>% +#' ) |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX") |> #' analyze(c("AGE")) #' #' tbl <- build_table(lyt, DM) @@ -1508,17 +1508,17 @@ setMethod( #' value. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("SEX") %>% -#' split_rows_by("RACE") %>% -#' summarize_row_groups() %>% -#' split_rows_by("STRATA1") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("SEX") |> +#' split_rows_by("RACE") |> +#' summarize_row_groups() |> +#' split_rows_by("STRATA1") |> #' analyze("AGE") #' #' @examplesIf require(dplyr) #' library(dplyr) ## for mutate -#' tbl <- build_table(lyt, DM %>% +#' tbl <- build_table(lyt, DM |> #' mutate(SEX = droplevels(SEX), RACE = droplevels(RACE))) #' #' row_paths_summary(tbl) diff --git a/R/tt_showmethods.R b/R/tt_showmethods.R index a0b3054547..0629ed6eeb 100644 --- a/R/tt_showmethods.R +++ b/R/tt_showmethods.R @@ -168,10 +168,10 @@ setMethod( #' a summary to the terminal. #' #' @examples -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_cols_by("STRATA1") %>% -#' split_cols_by("SEX", nested = FALSE) %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_cols_by("STRATA1") |> +#' split_cols_by("SEX", nested = FALSE) |> #' analyze("AGE") #' #' tbl <- build_table(lyt, ex_adsl) diff --git a/R/tt_sort.R b/R/tt_sort.R index 1ed10e5753..84081eed5f 100644 --- a/R/tt_sort.R +++ b/R/tt_sort.R @@ -137,19 +137,19 @@ match_fun_args <- function(fun, ...) { #' } #' #' # Main layout of the table -#' raw_lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% +#' raw_lyt <- basic_table() |> +#' split_cols_by("ARM") |> #' split_rows_by( #' "RACE", #' split_fun = drop_and_remove_levels("WHITE") # dropping WHITE levels -#' ) %>% -#' summarize_row_groups() %>% -#' split_rows_by("STRATA1") %>% -#' summarize_row_groups() %>% +#' ) |> +#' summarize_row_groups() |> +#' split_rows_by("STRATA1") |> +#' summarize_row_groups() |> #' analyze("AGE", afun = more_analysis_fnc) #' #' # Creating the table and pruning empty and NAs -#' tbl <- build_table(raw_lyt, DM) %>% +#' tbl <- build_table(raw_lyt, DM) |> #' prune_table() #' #' # Peek at the table structure to understand how it is built @@ -177,8 +177,8 @@ match_fun_args <- function(fun, ...) { #' } #' } #' -#' lyt2 <- basic_table() %>% -#' split_rows_by("SEX") %>% +#' lyt2 <- basic_table() |> +#' split_rows_by("SEX") |> #' analyze("AGE") #' #' tbl2 <- build_table(lyt2, DM) diff --git a/R/tt_toString.R b/R/tt_toString.R index 397e5a94a3..4119d455c7 100644 --- a/R/tt_toString.R +++ b/R/tt_toString.R @@ -24,14 +24,14 @@ NULL #' @examplesIf require(dplyr) #' library(dplyr) #' -#' iris2 <- iris %>% -#' group_by(Species) %>% -#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>% +#' iris2 <- iris |> +#' group_by(Species) |> +#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> #' ungroup() #' -#' lyt <- basic_table() %>% -#' split_cols_by("Species") %>% -#' split_cols_by("group") %>% +#' lyt <- basic_table() |> +#' split_cols_by("Species") |> +#' split_cols_by("group") |> #' analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") #' #' tbl <- build_table(lyt, iris2) @@ -85,14 +85,14 @@ setMethod("toString", "VTableTree", function(x, #' @examplesIf require(dplyr) #' library(dplyr) #' -#' iris2 <- iris %>% -#' group_by(Species) %>% -#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>% +#' iris2 <- iris |> +#' group_by(Species) |> +#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> #' ungroup() #' -#' lyt <- basic_table() %>% -#' split_cols_by("Species") %>% -#' split_cols_by("group") %>% +#' lyt <- basic_table() |> +#' split_cols_by("Species") |> +#' split_cols_by("group") |> #' analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") #' #' tbl <- build_table(lyt, iris2) @@ -180,14 +180,14 @@ table_shell_str <- function(tt, widths = NULL, col_gap = 3, hsep = default_hsep( #' @examplesIf require(dplyr) #' library(dplyr) #' -#' iris2 <- iris %>% -#' group_by(Species) %>% -#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>% +#' iris2 <- iris |> +#' group_by(Species) |> +#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> #' ungroup() #' -#' lyt <- basic_table() %>% -#' split_cols_by("Species") %>% -#' split_cols_by("group") %>% +#' lyt <- basic_table() |> +#' split_cols_by("Species") |> +#' split_cols_by("group") |> #' analyze(c("Sepal.Length", "Petal.Width"), #' afun = list_wrap_x(summary), format = "xx.xx" #' ) @@ -660,15 +660,15 @@ get_formatted_fnotes <- function(tt) { #' @examplesIf require(dplyr) #' library(dplyr) #' -#' iris2 <- iris %>% -#' group_by(Species) %>% -#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>% +#' iris2 <- iris |> +#' group_by(Species) |> +#' mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> #' ungroup() #' -#' tbl <- basic_table() %>% -#' split_cols_by("Species") %>% -#' split_cols_by("group") %>% -#' analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") %>% +#' tbl <- basic_table() |> +#' split_cols_by("Species") |> +#' split_cols_by("group") |> +#' analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") |> #' build_table(iris2) #' #' get_formatted_cells(tbl) diff --git a/R/utils.R b/R/utils.R index 933e160c70..728fa51228 100644 --- a/R/utils.R +++ b/R/utils.R @@ -125,12 +125,12 @@ func_takes <- function(func, params, is_first = FALSE) { } f_params <- formals(func) if (!is_first) { - return(setNames(params %in% names(f_params), params)) + setNames(params %in% names(f_params), params) } else { if (length(params) > 1L) { stop("is_first works only with one parameters.") } - return(!is.null(f_params) && names(f_params)[1] == params) + !is.null(f_params) && names(f_params)[1] == params } } diff --git a/R/validate_table_struct.R b/R/validate_table_struct.R index 3cf213d8ec..f804f0dd14 100644 --- a/R/validate_table_struct.R +++ b/R/validate_table_struct.R @@ -147,7 +147,7 @@ assert_valid_table <- function(tt, warn_only = FALSE) { stop(msg) } warning(msg) - return(FALSE) + FALSE } #' Sanitize degenerate table structures @@ -170,9 +170,9 @@ assert_valid_table <- function(tt, warn_only = FALSE) { #' @examples #' sanitize_table_struct(rtable("cool beans")) #' -#' lyt <- basic_table() %>% -#' split_cols_by("ARM") %>% -#' split_rows_by("SEX") %>% +#' lyt <- basic_table() |> +#' split_cols_by("ARM") |> +#' split_rows_by("SEX") |> #' summarize_row_groups() #' #' ## Degenerate because it doesn't have any analyze calls -> no data rows diff --git a/README.Rmd b/README.Rmd index fb61e16d6d..49b23765c9 100644 --- a/README.Rmd +++ b/README.Rmd @@ -93,8 +93,8 @@ We first demonstrate with a demographic table-like example and then show the cre ```{r, message=FALSE} library(rtables) -lyt <- basic_table() %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR1", "BMRKR2"), function(x, ...) { if (is.numeric(x)) { in_rows( @@ -118,7 +118,7 @@ library(rtables) library(dplyr) ## for simplicity grab non-sparse subset -ADSL <- ex_adsl %>% filter(RACE %in% levels(RACE)[1:3]) +ADSL <- ex_adsl |> filter(RACE %in% levels(RACE)[1:3]) biomarker_ave <- function(x, ...) { val <- if (length(x) > 0) round(mean(x), 2) else "no data" @@ -127,13 +127,13 @@ biomarker_ave <- function(x, ...) { ) } -basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_cols_by("BMRKR2") %>% - split_rows_by("RACE", split_fun = trim_levels_in_group("SEX")) %>% - split_rows_by("SEX") %>% - summarize_row_groups() %>% - analyze("BMRKR1", biomarker_ave) %>% +basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_cols_by("BMRKR2") |> + split_rows_by("RACE", split_fun = trim_levels_in_group("SEX")) |> + split_rows_by("SEX") |> + summarize_row_groups() |> + analyze("BMRKR1", biomarker_ave) |> build_table(ADSL) ``` diff --git a/README.md b/README.md index 7b6ed13f4e..ba637b57db 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,8 @@ the creation of a more complex table. ``` r library(rtables) -lyt <- basic_table() %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR1", "BMRKR2"), function(x, ...) { if (is.numeric(x)) { in_rows( @@ -150,7 +150,7 @@ library(rtables) library(dplyr) ## for simplicity grab non-sparse subset -ADSL <- ex_adsl %>% filter(RACE %in% levels(RACE)[1:3]) +ADSL <- ex_adsl |> filter(RACE %in% levels(RACE)[1:3]) biomarker_ave <- function(x, ...) { val <- if (length(x) > 0) round(mean(x), 2) else "no data" @@ -159,13 +159,13 @@ biomarker_ave <- function(x, ...) { ) } -basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_cols_by("BMRKR2") %>% - split_rows_by("RACE", split_fun = trim_levels_in_group("SEX")) %>% - split_rows_by("SEX") %>% - summarize_row_groups() %>% - analyze("BMRKR1", biomarker_ave) %>% +basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_cols_by("BMRKR2") |> + split_rows_by("RACE", split_fun = trim_levels_in_group("SEX")) |> + split_rows_by("SEX") |> + summarize_row_groups() |> + analyze("BMRKR1", biomarker_ave) |> build_table(ADSL) #> A: Drug X B: Placebo C: Combination #> LOW MEDIUM HIGH LOW MEDIUM HIGH LOW MEDIUM HIGH diff --git a/inst/WORDLIST b/inst/WORDLIST index 101cfef1fd..e4c6a3881b 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -114,3 +114,4 @@ useR visibilities visibilty xtable +Tord diff --git a/man/Viewer.Rd b/man/Viewer.Rd index 15f68f107f..b0b15aaa67 100644 --- a/man/Viewer.Rd +++ b/man/Viewer.Rd @@ -28,8 +28,8 @@ if (interactive()) { df <- cbind(iris, sl5 = sl5) - lyt <- basic_table() \%>\% - split_cols_by("sl5") \%>\% + lyt <- basic_table() |> + split_cols_by("sl5") |> analyze("Sepal.Length") tbl <- build_table(lyt, df) diff --git a/man/add_colcounts.Rd b/man/add_colcounts.Rd index 4238a9a123..d4d0e0bc70 100644 --- a/man/add_colcounts.Rd +++ b/man/add_colcounts.Rd @@ -26,10 +26,10 @@ For example, if events are counted in the table and the header should display the number of subjects and not the total number of events. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - add_colcounts() \%>\% - split_rows_by("RACE", split_fun = drop_split_levels) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + add_colcounts() |> + split_rows_by("RACE", split_fun = drop_split_levels) |> analyze("AGE", afun = function(x) list(min = min(x), max = max(x))) lyt diff --git a/man/add_combo_facet.Rd b/man/add_combo_facet.Rd index 9ac9e18488..a4a74b0d62 100644 --- a/man/add_combo_facet.Rd +++ b/man/add_combo_facet.Rd @@ -38,8 +38,8 @@ mysplfun <- make_split_fun(post = list( add_overall_facet("ALL", label = "All Arms") )) -lyt <- basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM", split_fun = mysplfun) \%>\% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = mysplfun) |> analyze("AGE") tbl <- build_table(lyt, DM) diff --git a/man/add_existing_table.Rd b/man/add_existing_table.Rd index d4612eb950..54798d8352 100644 --- a/man/add_existing_table.Rd +++ b/man/add_existing_table.Rd @@ -22,16 +22,16 @@ A \code{PreDataTableLayouts} object suitable for passing to further layouting fu Add an already calculated table to the layout } \examples{ -lyt1 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt1 <- basic_table() |> + split_cols_by("ARM") |> analyze("AGE", afun = mean, format = "xx.xx") tbl1 <- build_table(lyt1, DM) tbl1 -lyt2 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - analyze("AGE", afun = sd, format = "xx.xx") \%>\% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> + analyze("AGE", afun = sd, format = "xx.xx") |> add_existing_table(tbl1) tbl2 <- build_table(lyt2, DM) diff --git a/man/add_overall_col.Rd b/man/add_overall_col.Rd index ad107d0fba..5061d8fd1d 100644 --- a/man/add_overall_col.Rd +++ b/man/add_overall_col.Rd @@ -19,9 +19,9 @@ This function will \emph{only} add an overall column at the \emph{top} level of See \code{\link[=add_overall_level]{add_overall_level()}} for the recommended way to add overall columns more generally within existing splits. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - add_overall_col("All Patients") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + add_overall_col("All Patients") |> analyze("AGE") lyt diff --git a/man/add_overall_level.Rd b/man/add_overall_level.Rd index a978e17be0..9c9d782cd3 100644 --- a/man/add_overall_level.Rd +++ b/man/add_overall_level.Rd @@ -53,21 +53,21 @@ your custom split function if you need more flexibility (see \link{custom_split_ Analysis or summary functions for which the order matters should never be used within the tabulation framework. } \examples{ -lyt <- basic_table() \%>\% +lyt <- basic_table() |> split_cols_by("ARM", split_fun = add_overall_level("All Patients", first = FALSE - )) \%>\% + )) |> analyze("AGE") tbl <- build_table(lyt, DM) tbl -lyt2 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> split_rows_by("RACE", split_fun = add_overall_level("All Ethnicities") - ) \%>\% - summarize_row_groups(label_fstr = "\%s (n)") \%>\% + ) |> + summarize_row_groups(label_fstr = "\%s (n)") |> analyze("AGE") lyt2 @@ -83,14 +83,14 @@ combodf <- tribble( "A_C", "Arms A+C", c("A: Drug X", "C: Combination"), list() ) -lyt <- basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM", split_fun = add_combo_levels(combodf)) \%>\% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = add_combo_levels(combodf)) |> analyze("AGE") tbl <- build_table(lyt, DM) tbl -lyt1 <- basic_table(show_colcounts = TRUE) \%>\% +lyt1 <- basic_table(show_colcounts = TRUE) |> split_cols_by("ARM", split_fun = add_combo_levels(combodf, keep_levels = c( @@ -98,7 +98,7 @@ lyt1 <- basic_table(show_colcounts = TRUE) \%>\% "A_C" ) ) - ) \%>\% + ) |> analyze("AGE") tbl1 <- build_table(lyt1, DM) @@ -106,19 +106,19 @@ tbl1 smallerDM <- droplevels(subset(DM, SEX \%in\% c("M", "F") & grepl("^(A|B)", ARM))) -lyt2 <- basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM", split_fun = add_combo_levels(combodf[1, ])) \%>\% +lyt2 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = add_combo_levels(combodf[1, ])) |> split_cols_by("SEX", split_fun = add_overall_level("SEX_ALL", "All Genders") - ) \%>\% + ) |> analyze("AGE") -lyt3 <- basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM", split_fun = add_combo_levels(combodf)) \%>\% +lyt3 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = add_combo_levels(combodf)) |> split_rows_by("SEX", split_fun = add_overall_level("SEX_ALL", "All Genders") - ) \%>\% - summarize_row_groups() \%>\% + ) |> + summarize_row_groups() |> analyze("AGE") tbl3 <- build_table(lyt3, smallerDM) diff --git a/man/analyze.Rd b/man/analyze.Rd index 269e8207d7..378dc14d40 100644 --- a/man/analyze.Rd +++ b/man/analyze.Rd @@ -185,16 +185,16 @@ machinery. These are listed and described in \link{additional_fun_params}. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") lyt tbl <- build_table(lyt, DM) tbl -lyt2 <- basic_table() \%>\% - split_cols_by("Species") \%>\% +lyt2 <- basic_table() |> + split_cols_by("Species") |> analyze(head(names(iris), -1), afun = function(x) { list( "mean / sd" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), diff --git a/man/analyze_colvars.Rd b/man/analyze_colvars.Rd index 6726f7578d..9c7a1bc2dd 100644 --- a/man/analyze_colvars.Rd +++ b/man/analyze_colvars.Rd @@ -60,7 +60,7 @@ Generate rows analyzing different variables across columns \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -ANL <- DM \%>\% mutate(value = rnorm(n()), pctdiff = runif(n())) +ANL <- DM |> mutate(value = rnorm(n()), pctdiff = runif(n())) ## toy example where we take the mean of the first variable and the ## count of >.5 for the second. @@ -69,30 +69,30 @@ colfuns <- list( function(x) rcell(sum(x > .5), format = "xx") ) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by_multivar(c("value", "pctdiff")) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by_multivar(c("value", "pctdiff")) |> split_rows_by("RACE", split_label = "ethnicity", split_fun = drop_split_levels - ) \%>\% - summarize_row_groups() \%>\% + ) |> + summarize_row_groups() |> analyze_colvars(afun = colfuns) lyt tbl <- build_table(lyt, ANL) tbl -lyt2 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> split_cols_by_multivar(c("value", "pctdiff"), varlabels = c("Measurement", "Pct Diff") - ) \%>\% + ) |> split_rows_by("RACE", split_label = "ethnicity", split_fun = drop_split_levels - ) \%>\% - summarize_row_groups() \%>\% + ) |> + summarize_row_groups() |> analyze_colvars(afun = mean, format = "xx.xx") tbl2 <- build_table(lyt2, ANL) diff --git a/man/append_topleft.Rd b/man/append_topleft.Rd index 90f61aa060..4c2e086011 100644 --- a/man/append_topleft.Rd +++ b/man/append_topleft.Rd @@ -34,14 +34,14 @@ This function is experimental, its name and the details of its behavior are subj \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -DM2 <- DM \%>\% mutate(RACE = factor(RACE), SEX = factor(SEX)) +DM2 <- DM |> mutate(RACE = factor(RACE), SEX = factor(SEX)) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX") \%>\% - split_rows_by("RACE") \%>\% - append_topleft("Ethnicity") \%>\% - analyze("AGE") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> + split_rows_by("RACE") |> + append_topleft("Ethnicity") |> + analyze("AGE") |> append_topleft(" Age") tbl <- build_table(lyt, DM2) diff --git a/man/basic_table.Rd b/man/basic_table.Rd index 0ba10649fe..3958f813fb 100644 --- a/man/basic_table.Rd +++ b/man/basic_table.Rd @@ -79,7 +79,7 @@ indentation on multiple lines. } } \examples{ -lyt <- basic_table() \%>\% +lyt <- basic_table() |> analyze("AGE", afun = mean) tbl <- build_table(lyt, DM) @@ -93,8 +93,8 @@ lyt2 <- basic_table( "test.R program, executed at", Sys.time() ) -) \%>\% - split_cols_by("ARM") \%>\% +) |> + split_cols_by("ARM") |> analyze("AGE", mean) tbl2 <- build_table(lyt2, DM) @@ -103,7 +103,7 @@ tbl2 lyt3 <- basic_table( show_colcounts = TRUE, colcount_format = "xx. (xx.\%)" -) \%>\% +) |> split_cols_by("ARM") } diff --git a/man/brackets.Rd b/man/brackets.Rd index d550fa3248..5423f9f336 100644 --- a/man/brackets.Rd +++ b/man/brackets.Rd @@ -58,9 +58,9 @@ lyt <- basic_table( subtitles = c("Sub", "titles"), prov_footer = "prov footer", main_footer = "main footer" -) \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX") \%>\% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(c("AGE")) tbl <- build_table(lyt, DM) diff --git a/man/build_table.Rd b/man/build_table.Rd index 207dda9b24..9d80479efd 100644 --- a/man/build_table.Rd +++ b/man/build_table.Rd @@ -67,8 +67,8 @@ functions which accept \code{.N_col} and \code{.N_total} or do not rely on colum only way to ensure overridden counts are fully respected. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("Species") \%>\% +lyt <- basic_table() |> + split_cols_by("Species") |> analyze("Sepal.Length", afun = function(x) { list( "mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -81,8 +81,8 @@ tbl <- build_table(lyt, iris) tbl # analyze multiple variables -lyt2 <- basic_table() \%>\% - split_cols_by("Species") \%>\% +lyt2 <- basic_table() |> + split_cols_by("Species") |> analyze(c("Sepal.Length", "Petal.Width"), afun = function(x) { list( "mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -94,8 +94,8 @@ tbl2 <- build_table(lyt2, iris) tbl2 # an example more relevant for clinical trials with column counts -lyt3 <- basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM") \%>\% +lyt3 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> analyze("AGE", afun = function(x) { setNames(as.list(fivenum(x)), c( "minimum", "lower-hinge", "median", diff --git a/man/cell_values.Rd b/man/cell_values.Rd index 55151dceb5..6dd39f119b 100644 --- a/man/cell_values.Rd +++ b/man/cell_values.Rd @@ -39,17 +39,17 @@ Retrieve cell values by row and column path value. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX") \%>\% - split_rows_by("RACE") \%>\% - summarize_row_groups() \%>\% - split_rows_by("STRATA1") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> + split_rows_by("RACE") |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> analyze("AGE") \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) ## for mutate -tbl <- build_table(lyt, DM \%>\% +tbl <- build_table(lyt, DM |> mutate(SEX = droplevels(SEX), RACE = droplevels(RACE))) row_paths_summary(tbl) diff --git a/man/clear_imods.Rd b/man/clear_imods.Rd index cc80f8ca07..442b0386b6 100644 --- a/man/clear_imods.Rd +++ b/man/clear_imods.Rd @@ -22,10 +22,10 @@ The same class as \code{tt}, with all indent modifiers set to zero. Clear all indent modifiers from a table } \examples{ -lyt1 <- basic_table() \%>\% - summarize_row_groups("STUDYID", label_fstr = "overall summary") \%>\% - split_rows_by("AEBODSYS", child_labels = "visible") \%>\% - summarize_row_groups("STUDYID", label_fstr = "subgroup summary") \%>\% +lyt1 <- basic_table() |> + summarize_row_groups("STUDYID", label_fstr = "overall summary") |> + split_rows_by("AEBODSYS", child_labels = "visible") |> + summarize_row_groups("STUDYID", label_fstr = "subgroup summary") |> analyze("AGE", indent_mod = -1L) tbl1 <- build_table(lyt1, ex_adae) diff --git a/man/coltree_structure.Rd b/man/coltree_structure.Rd index 8a0e249509..ddc9927fa1 100644 --- a/man/coltree_structure.Rd +++ b/man/coltree_structure.Rd @@ -18,10 +18,10 @@ Displays the tree structure of the columns of a table or column structure object. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("STRATA1") \%>\% - split_cols_by("SEX", nested = FALSE) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("STRATA1") |> + split_cols_by("SEX", nested = FALSE) |> analyze("AGE") tbl <- build_table(lyt, ex_adsl) diff --git a/man/custom_split_funs.Rd b/man/custom_split_funs.Rd index 837622ff3c..aeb8659e41 100644 --- a/man/custom_split_funs.Rd +++ b/man/custom_split_funs.Rd @@ -73,9 +73,9 @@ d1 <- subset(d1, SEX \%in\% c("M", "F")) d1$SEX <- factor(d1$SEX) # This table uses the number of values in the SEX column to add the overall col or not -lyt <- basic_table() \%>\% - split_cols_by("ARM", split_fun = drop_split_levels) \%>\% - split_cols_by("SEX", split_fun = picky_splitter("SEX")) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM", split_fun = drop_split_levels) |> + split_cols_by("SEX", split_fun = picky_splitter("SEX")) |> analyze("AGE", show_labels = "visible") tbl <- build_table(lyt, d1) tbl diff --git a/man/data.frame_export.Rd b/man/data.frame_export.Rd index f6e621635f..b65afc44c7 100644 --- a/man/data.frame_export.Rd +++ b/man/data.frame_export.Rd @@ -91,16 +91,16 @@ df creation process, so the group values will be as if the relevant siblings had identical names. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("STRATA1") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("STRATA1") |> analyze(c("AGE", "BMRKR2")) tbl <- build_table(lyt, ex_adsl) as_result_df(tbl, simplify = TRUE) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR2")) tbl <- build_table(lyt, ex_adsl) diff --git a/man/dimensions.Rd b/man/dimensions.Rd index 49a92c4328..63bf1953a2 100644 --- a/man/dimensions.Rd +++ b/man/dimensions.Rd @@ -22,8 +22,8 @@ The number of rows (\code{nrow}), columns (\code{ncol}), or both (\code{dim}) of Table dimensions } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("SEX", "AGE")) tbl <- build_table(lyt, ex_adsl) diff --git a/man/do_base_split.Rd b/man/do_base_split.Rd index 40751fbfe6..2709a5583b 100644 --- a/man/do_base_split.Rd +++ b/man/do_base_split.Rd @@ -35,12 +35,12 @@ uneven_splfun <- function(df, spl, vals = NULL, labels = NULL, trim = FALSE) { ret } -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> split_cols_by_multivar(c("USUBJID", "AESEQ", "BMRKR1"), varlabels = c("N", "E", "BMR1"), split_fun = uneven_splfun - ) \%>\% + ) |> analyze_colvars(list( USUBJID = function(x, ...) length(unique(x)), AESEQ = max, diff --git a/man/facet_colcount.Rd b/man/facet_colcount.Rd index f2d5c318ce..d5348abfcb 100644 --- a/man/facet_colcount.Rd +++ b/man/facet_colcount.Rd @@ -64,13 +64,13 @@ will not always be simply the sum of the counts for all of its children. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM", show_colcounts = TRUE) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM", show_colcounts = TRUE) |> split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M")), show_colcounts = TRUE - ) \%>\% - split_cols_by("STRATA1", show_colcounts = TRUE) \%>\% + ) |> + split_cols_by("STRATA1", show_colcounts = TRUE) |> analyze("AGE") tbl <- build_table(lyt, ex_adsl) diff --git a/man/gfc.Rd b/man/gfc.Rd index 3ff2a2cf6c..494dc00da4 100644 --- a/man/gfc.Rd +++ b/man/gfc.Rd @@ -52,15 +52,15 @@ Get formatted cells \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -iris2 <- iris \%>\% - group_by(Species) \%>\% - mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) \%>\% +iris2 <- iris |> + group_by(Species) |> + mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> ungroup() -tbl <- basic_table() \%>\% - split_cols_by("Species") \%>\% - split_cols_by("group") \%>\% - analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") \%>\% +tbl <- basic_table() |> + split_cols_by("Species") |> + split_cols_by("group") |> + analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") |> build_table(iris2) get_formatted_cells(tbl) diff --git a/man/in_rows.Rd b/man/in_rows.Rd index 4867a041a1..c31e6d78de 100644 --- a/man/in_rows.Rd +++ b/man/in_rows.Rd @@ -69,8 +69,8 @@ in_rows(.list = list(a = c(NA, NA)), .format_na_strs = c("asda", "lkjklj")) in_rows(.list = list(a = 1, b = 2, c = 3)) in_rows(1, 2, .list = list(3), .names = c("a", "b", "c")) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze("AGE", afun = function(x) { in_rows( "Mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), diff --git a/man/insert_row_at_path.Rd b/man/insert_row_at_path.Rd index bb4ebe0265..515336b7b4 100644 --- a/man/insert_row_at_path.Rd +++ b/man/insert_row_at_path.Rd @@ -28,8 +28,8 @@ Insert a row into an existing table directly before or directly after an existin non-label) row, specified by its path. } \examples{ -lyt <- basic_table() \%>\% - split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) \%>\% +lyt <- basic_table() |> + split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) |> analyze("AGE") tbl <- build_table(lyt, DM) diff --git a/man/insert_rrow.Rd b/man/insert_rrow.Rd index 6a25aa49f0..40d1c2004d 100644 --- a/man/insert_rrow.Rd +++ b/man/insert_rrow.Rd @@ -31,8 +31,8 @@ not already contain a label row when there is a non-trivial nested row structure } \examples{ o <- options(warn = 0) -lyt <- basic_table() \%>\% - split_cols_by("Species") \%>\% +lyt <- basic_table() |> + split_cols_by("Species") |> analyze("Sepal.Length") tbl <- build_table(lyt, iris) @@ -40,9 +40,9 @@ tbl <- build_table(lyt, iris) insert_rrow(tbl, rrow("Hello World")) insert_rrow(tbl, rrow("Hello World"), at = 2) -lyt2 <- basic_table() \%>\% - split_cols_by("Species") \%>\% - split_rows_by("Species") \%>\% +lyt2 <- basic_table() |> + split_cols_by("Species") |> + split_rows_by("Species") |> analyze("Sepal.Length") tbl2 <- build_table(lyt2, iris) diff --git a/man/int_methods.Rd b/man/int_methods.Rd index eed80b0d9c..b585e744cb 100644 --- a/man/int_methods.Rd +++ b/man/int_methods.Rd @@ -1296,14 +1296,14 @@ attention to this documentation. \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -iris2 <- iris \%>\% - group_by(Species) \%>\% - mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) \%>\% +iris2 <- iris |> + group_by(Species) |> + mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> ungroup() -lyt <- basic_table() \%>\% - split_cols_by("Species") \%>\% - split_cols_by("group") \%>\% +lyt <- basic_table() |> + split_cols_by("Species") |> + split_cols_by("group") |> analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx" @@ -1311,8 +1311,8 @@ 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"))) \%>\% +lyt <- basic_table() |> + split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) |> analyze("AGE") tbl <- build_table(lyt, DM) diff --git a/man/label_at_path.Rd b/man/label_at_path.Rd index 7d5eba5f4b..7dfa41b6fd 100644 --- a/man/label_at_path.Rd +++ b/man/label_at_path.Rd @@ -33,8 +33,8 @@ ending in \code{"@content"} will not exhibit the behavior you want, and are thus determining the full paths to content rows. } \examples{ -lyt <- basic_table() \%>\% - split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) \%>\% +lyt <- basic_table() |> + split_rows_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) |> analyze("AGE") tbl <- build_table(lyt, DM) diff --git a/man/make_col_row_df.Rd b/man/make_col_row_df.Rd index d3256d3f02..57d47df12c 100644 --- a/man/make_col_row_df.Rd +++ b/man/make_col_row_df.Rd @@ -19,8 +19,8 @@ A list of paths to each row/column within \code{x}. Get a list of table row/column paths } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("SEX", "AGE")) tbl <- build_table(lyt, ex_adsl) diff --git a/man/make_split_fun.Rd b/man/make_split_fun.Rd index 2c62183979..8c6c953532 100644 --- a/man/make_split_fun.Rd +++ b/man/make_split_fun.Rd @@ -66,9 +66,9 @@ mysplitfun <- make_split_fun( post = list(add_overall_facet("ALL", "All Arms")) ) -basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM", split_fun = mysplitfun) \%>\% - analyze("AGE") \%>\% +basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = mysplitfun) |> + analyze("AGE") |> build_table(subset(DM, ARM \%in\% c("B: Placebo", "C: Combination"))) ## post (and pre) arguments can take multiple functions, here @@ -89,9 +89,9 @@ mysplitfun2 <- make_split_fun( reorder_facets ) ) -basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM", split_fun = mysplitfun2) \%>\% - analyze("AGE") \%>\% +basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = mysplitfun2) |> + analyze("AGE") |> build_table(subset(DM, ARM \%in\% c("B: Placebo", "C: Combination"))) very_stupid_core <- function(spl, df, vals, labels, .spl_context) { @@ -113,9 +113,9 @@ nonsense_splfun <- make_split_fun( ## recall core split overriding is not supported in column space ## currently, but we can see it in action in row space -lyt_silly <- basic_table() \%>\% - split_rows_by("ARM", split_fun = nonsense_splfun) \%>\% - summarize_row_groups() \%>\% +lyt_silly <- basic_table() |> + split_rows_by("ARM", split_fun = nonsense_splfun) |> + summarize_row_groups() |> analyze("AGE") silly_table <- build_table(lyt_silly, DM) silly_table diff --git a/man/matrix_form-VTableTree-method.Rd b/man/matrix_form-VTableTree-method.Rd index f140a47387..482b5508cb 100644 --- a/man/matrix_form-VTableTree-method.Rd +++ b/man/matrix_form-VTableTree-method.Rd @@ -62,14 +62,14 @@ function. \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -iris2 <- iris \%>\% - group_by(Species) \%>\% - mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) \%>\% +iris2 <- iris |> + group_by(Species) |> + mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> ungroup() -lyt <- basic_table() \%>\% - split_cols_by("Species") \%>\% - split_cols_by("group") \%>\% +lyt <- basic_table() |> + split_cols_by("Species") |> + split_cols_by("group") |> analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx" ) diff --git a/man/paginate.Rd b/man/paginate.Rd index d0ac792301..803ffe488b 100644 --- a/man/paginate.Rd +++ b/man/paginate.Rd @@ -210,8 +210,8 @@ s_summary <- function(x) { } } -lyt <- basic_table() \%>\% - split_cols_by(var = "ARM") \%>\% +lyt <- basic_table() |> + split_cols_by(var = "ARM") |> analyze(c("AGE", "SEX", "BEP01FL", "BMRKR1", "BMRKR2", "COUNTRY"), afun = s_summary) tbl <- build_table(lyt, ex_adsl) diff --git a/man/prune_table.Rd b/man/prune_table.Rd index ab60004cd1..380f522589 100644 --- a/man/prune_table.Rd +++ b/man/prune_table.Rd @@ -36,16 +36,16 @@ Recursively prune a \code{TableTree} adsl <- ex_adsl levels(adsl$SEX) <- c(levels(ex_adsl$SEX), "OTHER") -tbl_to_prune <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX") \%>\% - summarize_row_groups() \%>\% - split_rows_by("STRATA1") \%>\% - summarize_row_groups() \%>\% - analyze("AGE") \%>\% +tbl_to_prune <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> + summarize_row_groups() |> + analyze("AGE") |> build_table(adsl) -tbl_to_prune \%>\% prune_table() +tbl_to_prune |> prune_table() } \seealso{ diff --git a/man/reexports.Rd b/man/reexports.Rd index 04c055889b..c9ba47d925 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -7,8 +7,8 @@ \alias{export_as_pdf} \title{Objects exported from other packages} \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR2", "COUNTRY")) tbl <- build_table(lyt, ex_adsl) @@ -21,8 +21,8 @@ export_as_txt(tbl, file = tf) system2("cat", tf) } -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR2", "COUNTRY")) tbl <- build_table(lyt, ex_adsl) diff --git a/man/ref_fnotes.Rd b/man/ref_fnotes.Rd index a6948bdec6..89e248df50 100644 --- a/man/ref_fnotes.Rd +++ b/man/ref_fnotes.Rd @@ -67,8 +67,8 @@ Access and set the referential footnotes aspects of a built table. } \examples{ # How to add referencial footnotes after having created a table -lyt <- basic_table() \%>\% - split_rows_by("SEX", page_by = TRUE) \%>\% +lyt <- basic_table() |> + split_rows_by("SEX", page_by = TRUE) |> analyze("AGE") tbl <- build_table(lyt, DM) diff --git a/man/rm_all_colcounts.Rd b/man/rm_all_colcounts.Rd index 463b76593f..043c9fb58c 100644 --- a/man/rm_all_colcounts.Rd +++ b/man/rm_all_colcounts.Rd @@ -28,9 +28,9 @@ rm_all_colcounts(obj) Set all column counts at all levels of nesting to NA } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> analyze("AGE") tbl <- build_table(lyt, ex_adsl) diff --git a/man/row_paths_summary.Rd b/man/row_paths_summary.Rd index 1835aea04a..d79e1dbbf7 100644 --- a/man/row_paths_summary.Rd +++ b/man/row_paths_summary.Rd @@ -20,11 +20,11 @@ Print row/column paths summary } \examples{ \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} -ex_adsl_MF <- ex_adsl \%>\% dplyr::filter(SEX \%in\% c("M", "F")) +ex_adsl_MF <- ex_adsl |> dplyr::filter(SEX \%in\% c("M", "F")) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX", split_fun = drop_split_levels) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX", split_fun = drop_split_levels) |> analyze(c("AGE", "BMRKR2")) tbl <- build_table(lyt, ex_adsl_MF) diff --git a/man/rtables-package.Rd b/man/rtables-package.Rd index dd6327e07d..fa8a836607 100644 --- a/man/rtables-package.Rd +++ b/man/rtables-package.Rd @@ -36,6 +36,7 @@ Other contributors: \item Daniel Sabanés Bové \email{daniel.sabanes_bove@rconis.com} [contributor] \item Maximilian Mordig \email{maximilian_oliver.mordig@roche.com} [contributor] \item Abinaya Yogasekaram \email{ayogasek@gmail.com} (\href{https://orcid.org/0009-0005-2083-1105}{ORCID}) [contributor] + \item David Munoz Tord \email{david.munoztord@mailbox.org} [contributor] \item F. Hoffmann-La Roche AG [copyright holder, funder] } diff --git a/man/sanitize_table_struct.Rd b/man/sanitize_table_struct.Rd index 64eb0e14e2..90c9e2ba45 100644 --- a/man/sanitize_table_struct.Rd +++ b/man/sanitize_table_struct.Rd @@ -28,9 +28,9 @@ guaranteed to be non-degenerate. \examples{ sanitize_table_struct(rtable("cool beans")) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> summarize_row_groups() ## Degenerate because it doesn't have any analyze calls -> no data rows diff --git a/man/section_div.Rd b/man/section_div.Rd index 993a520c59..f1da79398c 100644 --- a/man/section_div.Rd +++ b/man/section_div.Rd @@ -225,9 +225,9 @@ df <- data.frame( ) fast_afun <- function(x) list("m" = rcell(mean(x), format = "xx."), "m/2" = max(x) / 2) -tbl <- basic_table() \%>\% - split_rows_by("cat", section_div = "~") \%>\% - analyze("value", afun = fast_afun, section_div = " ") \%>\% +tbl <- basic_table() |> + split_rows_by("cat", section_div = "~") |> + analyze("value", afun = fast_afun, section_div = " ") |> build_table(df) # Getter diff --git a/man/sort_at_path.Rd b/man/sort_at_path.Rd index 503c4524a0..5a3aecbfad 100644 --- a/man/sort_at_path.Rd +++ b/man/sort_at_path.Rd @@ -103,19 +103,19 @@ more_analysis_fnc <- function(x) { } # Main layout of the table -raw_lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +raw_lyt <- basic_table() |> + split_cols_by("ARM") |> split_rows_by( "RACE", split_fun = drop_and_remove_levels("WHITE") # dropping WHITE levels - ) \%>\% - summarize_row_groups() \%>\% - split_rows_by("STRATA1") \%>\% - summarize_row_groups() \%>\% + ) |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> + summarize_row_groups() |> analyze("AGE", afun = more_analysis_fnc) # Creating the table and pruning empty and NAs -tbl <- build_table(raw_lyt, DM) \%>\% +tbl <- build_table(raw_lyt, DM) |> prune_table() # Peek at the table structure to understand how it is built @@ -143,8 +143,8 @@ last_cat_scorefun <- function(x, decreasing, lastcat) { } } -lyt2 <- basic_table() \%>\% - split_rows_by("SEX") \%>\% +lyt2 <- basic_table() |> + split_rows_by("SEX") |> analyze("AGE") tbl2 <- build_table(lyt2, DM) diff --git a/man/split_cols_by.Rd b/man/split_cols_by.Rd index a2ecc5793e..d65a2591b2 100644 --- a/man/split_cols_by.Rd +++ b/man/split_cols_by.Rd @@ -97,8 +97,8 @@ data before they are called or their outputs. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR2")) tbl <- build_table(lyt, ex_adsl) @@ -106,11 +106,11 @@ tbl # Let's look at the splits in more detail -lyt1 <- basic_table() \%>\% split_cols_by("ARM") +lyt1 <- basic_table() |> split_cols_by("ARM") lyt1 # add an analysis (summary) -lyt2 <- lyt1 \%>\% +lyt2 <- lyt1 |> analyze(c("AGE", "COUNTRY"), afun = list_wrap_x(summary), format = "xx.xx" @@ -124,13 +124,13 @@ tbl2 # By default sequentially adding layouts results in nesting library(dplyr) -DM_MF <- DM \%>\% - filter(SEX \%in\% c("M", "F")) \%>\% +DM_MF <- DM |> + filter(SEX \%in\% c("M", "F")) |> mutate(SEX = droplevels(SEX)) -lyt3 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX") \%>\% +lyt3 <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> analyze(c("AGE", "COUNTRY"), afun = list_wrap_x(summary), format = "xx.xx" @@ -141,21 +141,21 @@ tbl3 <- build_table(lyt3, DM_MF) tbl3 # nested=TRUE vs not -lyt4 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX", split_fun = drop_split_levels) \%>\% - split_rows_by("RACE", split_fun = drop_split_levels) \%>\% +lyt4 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> + split_rows_by("RACE", split_fun = drop_split_levels) |> analyze("AGE") lyt4 tbl4 <- build_table(lyt4, DM) tbl4 -lyt5 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX", split_fun = drop_split_levels) \%>\% - analyze("AGE") \%>\% - split_rows_by("RACE", nested = FALSE, split_fun = drop_split_levels) \%>\% +lyt5 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> + analyze("AGE") |> + split_rows_by("RACE", nested = FALSE, split_fun = drop_split_levels) |> analyze("AGE") lyt5 diff --git a/man/split_cols_by_multivar.Rd b/man/split_cols_by_multivar.Rd index 7aca062757..98a249f6ba 100644 --- a/man/split_cols_by_multivar.Rd +++ b/man/split_cols_by_multivar.Rd @@ -56,7 +56,7 @@ variable, we use \code{split_cols_by_multivar}. \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -ANL <- DM \%>\% mutate(value = rnorm(n()), pctdiff = runif(n())) +ANL <- DM |> mutate(value = rnorm(n()), pctdiff = runif(n())) ## toy example where we take the mean of the first variable and the ## count of >.5 for the second. @@ -65,14 +65,14 @@ colfuns <- list( function(x) in_rows("# x > 5" = sum(x > .5), .formats = "xx") ) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by_multivar(c("value", "pctdiff")) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by_multivar(c("value", "pctdiff")) |> split_rows_by("RACE", split_label = "ethnicity", split_fun = drop_split_levels - ) \%>\% - summarize_row_groups() \%>\% + ) |> + summarize_row_groups() |> analyze_colvars(afun = colfuns) lyt diff --git a/man/split_funcs.Rd b/man/split_funcs.Rd index ea20a382c7..5e8c301fbd 100644 --- a/man/split_funcs.Rd +++ b/man/split_funcs.Rd @@ -100,60 +100,60 @@ and \code{\link[=make_split_fun]{make_split_fun()}} for a more advanced API. } \examples{ # keep_split_levels keeps specified levels (reorder = TRUE by default) -lyt <- basic_table() \%>\% +lyt <- basic_table() |> split_rows_by("COUNTRY", split_fun = keep_split_levels(c("USA", "CAN", "BRA")) - ) \%>\% + ) |> analyze("AGE") tbl <- build_table(lyt, DM) tbl # remove_split_levels removes specified split levels -lyt <- basic_table() \%>\% +lyt <- basic_table() |> split_rows_by("COUNTRY", split_fun = remove_split_levels(c( "USA", "CAN", "CHE", "BRA" )) - ) \%>\% + ) |> analyze("AGE") tbl <- build_table(lyt, DM) tbl # drop_split_levels drops levels that are not present in the data -lyt <- basic_table() \%>\% - split_rows_by("SEX", split_fun = drop_split_levels) \%>\% +lyt <- basic_table() |> + split_rows_by("SEX", split_fun = drop_split_levels) |> analyze("AGE") tbl <- build_table(lyt, DM) tbl # Removing "M" and "U" directly, then "UNDIFFERENTIATED" because not in data -lyt <- basic_table() \%>\% - split_rows_by("SEX", split_fun = drop_and_remove_levels(c("M", "U"))) \%>\% +lyt <- basic_table() |> + split_rows_by("SEX", split_fun = drop_and_remove_levels(c("M", "U"))) |> analyze("AGE") tbl <- build_table(lyt, DM) tbl # Reordering levels in split variable -lyt <- basic_table() \%>\% +lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( neworder = c("U", "F"), newlabels = c(U = "Uu", `F` = "Female") ) - ) \%>\% + ) |> analyze("AGE") tbl <- build_table(lyt, DM) tbl # Reordering levels in split variable but keeping all the levels -lyt <- basic_table() \%>\% +lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( @@ -161,7 +161,7 @@ lyt <- basic_table() \%>\% newlabels = c("Uu", "Female"), drlevels = FALSE ) - ) \%>\% + ) |> analyze("AGE") tbl <- build_table(lyt, DM) @@ -173,9 +173,9 @@ dat <- data.frame( col2 = factor(c("a", "b", "c"), levels = c("a", "b", "c", "x")) ) # N is removed if drop_outlevs = TRUE, x is removed always -tbl <- basic_table() \%>\% - split_rows_by("col1", split_fun = trim_levels_in_group("col2")) \%>\% - analyze("col2") \%>\% +tbl <- basic_table() |> + split_rows_by("col1", split_fun = trim_levels_in_group("col2")) |> + analyze("col2") |> build_table(dat) tbl diff --git a/man/split_rows_by.Rd b/man/split_rows_by.Rd index 1392450880..2069ca88e9 100644 --- a/man/split_rows_by.Rd +++ b/man/split_rows_by.Rd @@ -117,31 +117,31 @@ data before they are called or their outputs. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("RACE", split_fun = drop_split_levels) \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE", split_fun = drop_split_levels) |> analyze("AGE", mean, var_labels = "Age", format = "xx.xx") tbl <- build_table(lyt, DM) tbl -lyt2 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("RACE") \%>\% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE") |> analyze("AGE", mean, var_labels = "Age", format = "xx.xx") tbl2 <- build_table(lyt2, DM) tbl2 -lyt3 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX") \%>\% - summarize_row_groups(label_fstr = "Overall (N)") \%>\% +lyt3 <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> + summarize_row_groups(label_fstr = "Overall (N)") |> split_rows_by("RACE", split_label = "Ethnicity", labels_var = "ethn_lab", split_fun = drop_split_levels - ) \%>\% - summarize_row_groups("RACE", label_fstr = "\%s (n)") \%>\% + ) |> + summarize_row_groups("RACE", label_fstr = "\%s (n)") |> analyze("AGE", var_labels = "Age", afun = mean, format = "xx.xx") lyt3 @@ -149,8 +149,8 @@ lyt3 \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -DM2 <- DM \%>\% - filter(SEX \%in\% c("M", "F")) \%>\% +DM2 <- DM |> + filter(SEX \%in\% c("M", "F")) |> mutate( SEX = droplevels(SEX), gender_lab = c( diff --git a/man/split_rows_by_multivar.Rd b/man/split_rows_by_multivar.Rd index 389d351e43..2e99b223d0 100644 --- a/man/split_rows_by_multivar.Rd +++ b/man/split_rows_by_multivar.Rd @@ -70,10 +70,10 @@ When we need rows to reflect different variables rather than different levels of a single variable, we use \code{split_rows_by_multivar}. } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by_multivar(c("SEX", "STRATA1")) \%>\% - summarize_row_groups() \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by_multivar(c("SEX", "STRATA1")) |> + summarize_row_groups() |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, DM) diff --git a/man/subset_cols.Rd b/man/subset_cols.Rd index 5bb88207de..b32da64f03 100644 --- a/man/subset_cols.Rd +++ b/man/subset_cols.Rd @@ -121,9 +121,9 @@ lyt <- basic_table( subtitles = c("Sub", "titles"), prov_footer = "prov footer", main_footer = "main footer" -) \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX") \%>\% +) |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> analyze(c("AGE")) tbl <- build_table(lyt, DM) diff --git a/man/summarize_row_groups.Rd b/man/summarize_row_groups.Rd index 4839be826d..ecefc36740 100644 --- a/man/summarize_row_groups.Rd +++ b/man/summarize_row_groups.Rd @@ -65,10 +65,10 @@ that can be used in \code{cfun}. \examples{ DM2 <- subset(DM, COUNTRY \%in\% c("USA", "CAN", "CHN")) -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("COUNTRY", split_fun = drop_split_levels) \%>\% - summarize_row_groups(label_fstr = "\%s (n)") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("COUNTRY", split_fun = drop_split_levels) |> + summarize_row_groups(label_fstr = "\%s (n)") |> analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") lyt @@ -90,14 +90,14 @@ sfun <- function(x, labelstr, trim) { ) } -lyt2 <- basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("COUNTRY", split_fun = drop_split_levels) \%>\% +lyt2 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_rows_by("COUNTRY", split_fun = drop_split_levels) |> summarize_row_groups("AGE", cfun = sfun, extra_args = list(trim = .2) - ) \%>\% - analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") \%>\% + ) |> + analyze("AGE", afun = list_wrap_x(summary), format = "xx.xx") |> append_topleft(c("Country", " Age")) tbl2 <- build_table(lyt2, DM2) diff --git a/man/table_shell.Rd b/man/table_shell.Rd index bd310700c5..a5d0398e86 100644 --- a/man/table_shell.Rd +++ b/man/table_shell.Rd @@ -57,14 +57,14 @@ displaying the formatting instructions for each cell. \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -iris2 <- iris \%>\% - group_by(Species) \%>\% - mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) \%>\% +iris2 <- iris |> + group_by(Species) |> + mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> ungroup() -lyt <- basic_table() \%>\% - split_cols_by("Species") \%>\% - split_cols_by("group") \%>\% +lyt <- basic_table() |> + split_cols_by("Species") |> + split_cols_by("group") |> analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") tbl <- build_table(lyt, iris2) diff --git a/man/table_structure.Rd b/man/table_structure.Rd index 1940cd0371..1398cc57fa 100644 --- a/man/table_structure.Rd +++ b/man/table_structure.Rd @@ -21,14 +21,14 @@ Summarize table \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -iris2 <- iris \%>\% - group_by(Species) \%>\% - mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) \%>\% +iris2 <- iris |> + group_by(Species) |> + mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> ungroup() -lyt <- basic_table() \%>\% - split_cols_by("Species") \%>\% - split_cols_by("group") \%>\% +lyt <- basic_table() |> + split_cols_by("Species") |> + split_cols_by("group") |> analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx" diff --git a/man/tostring.Rd b/man/tostring.Rd index 159422a3f1..e016a60c85 100644 --- a/man/tostring.Rd +++ b/man/tostring.Rd @@ -72,14 +72,14 @@ case each string is word-wrapped separately with the behavior described above. \dontshow{if (require(dplyr)) withAutoprint(\{ # examplesIf} library(dplyr) -iris2 <- iris \%>\% - group_by(Species) \%>\% - mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) \%>\% +iris2 <- iris |> + group_by(Species) |> + mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) |> ungroup() -lyt <- basic_table() \%>\% - split_cols_by("Species") \%>\% - split_cols_by("group") \%>\% +lyt <- basic_table() |> + split_cols_by("Species") |> + split_cols_by("group") |> analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary), format = "xx.xx") tbl <- build_table(lyt, iris2) diff --git a/man/trim_levels_to_map.Rd b/man/trim_levels_to_map.Rd index 17399a63cb..f13569afef 100644 --- a/man/trim_levels_to_map.Rd +++ b/man/trim_levels_to_map.Rd @@ -39,9 +39,9 @@ map <- data.frame( stringsAsFactors = FALSE ) -lyt <- basic_table() \%>\% - split_rows_by("LBCAT") \%>\% - split_rows_by("PARAMCD", split_fun = trim_levels_to_map(map = map)) \%>\% +lyt <- basic_table() |> + split_rows_by("LBCAT") |> + split_rows_by("PARAMCD", split_fun = trim_levels_to_map(map = map)) |> analyze("ANRIND") tbl <- build_table(lyt, ex_adlb) diff --git a/man/trim_prune_funs.Rd b/man/trim_prune_funs.Rd index a03303df42..e2c21ffc01 100644 --- a/man/trim_prune_funs.Rd +++ b/man/trim_prune_funs.Rd @@ -71,28 +71,28 @@ levels(adsl$SEX) <- c(levels(ex_adsl$SEX), "OTHER") adsl$AGE[adsl$SEX == "UNDIFFERENTIATED"] <- 0 adsl$BMRKR1 <- 0 -tbl_to_prune <- basic_table() \%>\% - analyze("BMRKR1") \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX") \%>\% - summarize_row_groups() \%>\% - split_rows_by("STRATA1") \%>\% - summarize_row_groups() \%>\% - analyze("AGE") \%>\% +tbl_to_prune <- basic_table() |> + analyze("BMRKR1") |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> + summarize_row_groups() |> + analyze("AGE") |> build_table(adsl) -tbl_to_prune \%>\% prune_table(all_zero_or_na) +tbl_to_prune |> prune_table(all_zero_or_na) -tbl_to_prune \%>\% prune_table(all_zero) +tbl_to_prune |> prune_table(all_zero) -tbl_to_prune \%>\% prune_table(content_all_zeros_nas) +tbl_to_prune |> prune_table(content_all_zeros_nas) -tbl_to_prune \%>\% prune_table(prune_empty_level) +tbl_to_prune |> prune_table(prune_empty_level) -tbl_to_prune \%>\% prune_table(prune_zeros_only) +tbl_to_prune |> prune_table(prune_zeros_only) min_prune <- low_obs_pruner(70, "sum") -tbl_to_prune \%>\% prune_table(min_prune) +tbl_to_prune |> prune_table(min_prune) } \seealso{ diff --git a/man/trim_rows.Rd b/man/trim_rows.Rd index d96a125d72..a7c0152526 100644 --- a/man/trim_rows.Rd +++ b/man/trim_rows.Rd @@ -32,19 +32,19 @@ a \code{LabelRow} object. To avoid this, use the structurally-aware \code{\link[ adsl <- ex_adsl levels(adsl$SEX) <- c(levels(ex_adsl$SEX), "OTHER") -tbl_to_trim <- basic_table() \%>\% - analyze("BMRKR1") \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX") \%>\% - summarize_row_groups() \%>\% - split_rows_by("STRATA1") \%>\% - summarize_row_groups() \%>\% - analyze("AGE") \%>\% +tbl_to_trim <- basic_table() |> + analyze("BMRKR1") |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> + summarize_row_groups() |> + analyze("AGE") |> build_table(adsl) -tbl_to_trim \%>\% trim_rows() +tbl_to_trim |> trim_rows() -tbl_to_trim \%>\% trim_rows(all_zero) +tbl_to_trim |> trim_rows(all_zero) } \seealso{ diff --git a/man/ttap.Rd b/man/ttap.Rd index 592d5c4806..fcf045f889 100644 --- a/man/ttap.Rd +++ b/man/ttap.Rd @@ -27,13 +27,13 @@ Setting \code{NULL} at a defined path removes the corresponding sub-table. } \examples{ # Accessing sub table. -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX") \%>\% - split_rows_by("BMRKR2") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + split_rows_by("BMRKR2") |> analyze("AGE") -tbl <- build_table(lyt, ex_adsl) \%>\% prune_table() +tbl <- build_table(lyt, ex_adsl) |> prune_table() sub_tbl <- tt_at_path(tbl, path = c("SEX", "F", "BMRKR2")) # Removing sub table. @@ -42,12 +42,12 @@ tt_at_path(tbl2, path = c("SEX", "F")) <- NULL tbl2 # Setting sub table. -lyt3 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_rows_by("SEX") \%>\% +lyt3 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze("BMRKR2") -tbl3 <- build_table(lyt3, ex_adsl) \%>\% prune_table() +tbl3 <- build_table(lyt3, ex_adsl) |> prune_table() tt_at_path(tbl3, path = c("SEX", "F", "BMRKR2")) <- sub_tbl tbl3 diff --git a/man/value_formats.Rd b/man/value_formats.Rd index e0cd04b803..cc564799e2 100644 --- a/man/value_formats.Rd +++ b/man/value_formats.Rd @@ -31,8 +31,8 @@ Matrix (storage mode list) containing the effective format for each cell positio Returns a matrix of formats for the cells in a table. } \examples{ -lyt <- basic_table() \%>\% - split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) \%>\% +lyt <- basic_table() |> + split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) |> analyze("AGE") tbl <- build_table(lyt, DM) diff --git a/man/varcuts.Rd b/man/varcuts.Rd index c5b387c2a7..10aa405a95 100644 --- a/man/varcuts.Rd +++ b/man/varcuts.Rd @@ -172,28 +172,28 @@ the overall values (e.g., quartiles) in the dataset, NOT the values for subset i library(dplyr) # split_cols_by_cuts -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> split_cols_by_cuts("AGE", split_label = "Age", cuts = c(0, 25, 35, 1000), cutlabels = c("young", "medium", "old") - ) \%>\% - analyze(c("BMRKR2", "STRATA2")) \%>\% + ) |> + analyze(c("BMRKR2", "STRATA2")) |> append_topleft("counts") tbl <- build_table(lyt, ex_adsl) tbl # split_rows_by_cuts -lyt2 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> split_rows_by_cuts("AGE", split_label = "Age", cuts = c(0, 25, 35, 1000), cutlabels = c("young", "medium", "old") - ) \%>\% - analyze(c("BMRKR2", "STRATA2")) \%>\% + ) |> + analyze(c("BMRKR2", "STRATA2")) |> append_topleft("counts") @@ -202,20 +202,20 @@ tbl2 # split_cols_by_quartiles -lyt3 <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by_quartiles("AGE", split_label = "Age") \%>\% - analyze(c("BMRKR2", "STRATA2")) \%>\% +lyt3 <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by_quartiles("AGE", split_label = "Age") |> + analyze(c("BMRKR2", "STRATA2")) |> append_topleft("counts") tbl3 <- build_table(lyt3, ex_adsl) tbl3 # split_rows_by_quartiles -lyt4 <- basic_table(show_colcounts = TRUE) \%>\% - split_cols_by("ARM") \%>\% - split_rows_by_quartiles("AGE", split_label = "Age") \%>\% - analyze("BMRKR2") \%>\% +lyt4 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_rows_by_quartiles("AGE", split_label = "Age") |> + analyze("BMRKR2") |> append_topleft(c("Age Quartiles", " Counts BMRKR2")) tbl4 <- build_table(lyt4, ex_adsl) @@ -233,17 +233,17 @@ cutfun <- function(x) { cutpoints } -lyt5 <- basic_table() \%>\% - split_cols_by_cutfun("AGE", cutfun = cutfun) \%>\% +lyt5 <- basic_table() |> + split_cols_by_cutfun("AGE", cutfun = cutfun) |> analyze("SEX") tbl5 <- build_table(lyt5, ex_adsl) tbl5 # split_rows_by_cutfun -lyt6 <- basic_table() \%>\% - split_cols_by("SEX") \%>\% - split_rows_by_cutfun("AGE", cutfun = cutfun) \%>\% +lyt6 <- basic_table() |> + split_cols_by("SEX") |> + split_rows_by_cutfun("AGE", cutfun = cutfun) |> analyze("BMRKR2") tbl6 <- build_table(lyt6, ex_adsl) diff --git a/man/vil.Rd b/man/vil.Rd index 391cae8f94..d60f83aebe 100644 --- a/man/vil.Rd +++ b/man/vil.Rd @@ -51,15 +51,15 @@ or \code{df} and then rely on the existence of particular variables not being sp } } \examples{ -lyt <- basic_table() \%>\% - split_cols_by("ARM") \%>\% - split_cols_by("SEX") \%>\% - summarize_row_groups(label_fstr = "Overall (N)") \%>\% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> + summarize_row_groups(label_fstr = "Overall (N)") |> split_rows_by("RACE", split_label = "Ethnicity", labels_var = "ethn_lab", split_fun = drop_split_levels - ) \%>\% - summarize_row_groups("RACE", label_fstr = "\%s (n)") \%>\% + ) |> + summarize_row_groups("RACE", label_fstr = "\%s (n)") |> analyze("AGE", var_labels = "Age", afun = mean, format = "xx.xx") vars_in_layout(lyt) diff --git a/tests/testthat/test-as_html.R b/tests/testthat/test-as_html.R index d0db0349aa..07c450a5fc 100644 --- a/tests/testthat/test-as_html.R +++ b/tests/testthat/test-as_html.R @@ -24,8 +24,8 @@ test_that("as_html Viewer with newline test", { ) varlabs <- c("Mean Age", "SD\nLine Break!!! \nAge") - lyt <- basic_table() %>% - split_cols_by_multivar(c("AGE", "AGE"), varlabels = varlabs) %>% + lyt <- basic_table() |> + split_cols_by_multivar(c("AGE", "AGE"), varlabels = varlabs) |> analyze_colvars(afun = colfuns) tbl_wrapping <- build_table(lyt, DM) @@ -89,9 +89,9 @@ test_that("as_html header line works", { # https://github.com/insightsengineering/rtables/issues/872 test_that("as_html indentation is translated to rows with linebreaks", { - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze("AGE", afun = function(x) { mn <- round(mean(x), 2) if (!is.nan(mn) && mn > mean(DM$AGE)) { @@ -122,14 +122,14 @@ test_that("as_html expands or not newlines depending on expand_newlines", { require(dplyr, quietly = TRUE) # Table with both col/row names with newlines - iris_mod <- iris %>% - mutate(Species2 = as.factor(paste0("General", "\n ", as.character(Species)))) %>% + iris_mod <- iris |> + mutate(Species2 = as.factor(paste0("General", "\n ", as.character(Species)))) |> mutate(Species = as.factor(sample(paste0("Petal", "\n ", as.character(Species))))) # Also the statistic has a newline - lyt <- basic_table() %>% - split_cols_by("Species") %>% - split_rows_by("Species2") %>% + lyt <- basic_table() |> + split_cols_by("Species") |> + split_rows_by("Species2") |> analyze("Sepal.Length", afun = function(x) { list( "mean \n (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), diff --git a/tests/testthat/test-binding.R b/tests/testthat/test-binding.R index 98886b7902..b4b0cc24fa 100644 --- a/tests/testthat/test-binding.R +++ b/tests/testthat/test-binding.R @@ -46,12 +46,12 @@ test_that("mixing NA and non-NA counts and avars is ok", { iris2$manmade <- sample(c("Y", "N"), nrow(iris), replace = TRUE) # First case: no LabelRow objects (hidden) - rtb_t <- basic_table() %>% - split_cols_by("manmade") %>% + rtb_t <- basic_table() |> + split_cols_by("manmade") |> analyze( vars = colnames(iris)[1:3], afun = mean, format = "xx.x", show_labels = "hidden" - ) %>% + ) |> build_table(iris2) cinfo <- manual_cols("hiya") @@ -134,8 +134,8 @@ test_that("chk_cbindable_many works", { }) test_that("c/rbind and top-left behave", { - lyt <- basic_table() %>% - append_topleft("Hi") %>% + lyt <- basic_table() |> + append_topleft("Hi") |> analyze("AGE", mean) tab <- build_table(lyt, DM) @@ -169,9 +169,9 @@ test_that("c/rbind and top-left behave", { ## NB: insert_rrow is now deprecated. test_that("insert_rrow works", { - tbl <- basic_table() %>% - split_cols_by("ARM") %>% - analyze("AGE") %>% + tbl <- basic_table() |> + split_cols_by("ARM") |> + analyze("AGE") |> build_table(ex_adsl) ## column numbers don't match @@ -181,16 +181,16 @@ test_that("insert_rrow works", { }) test_that("count visibility syncing works when cbinding", { - lyt1 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA1") %>% + lyt1 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_cols_by("STRATA1") |> analyze("AGE") tab1 <- build_table(lyt1, ex_adsl) - lyt2 <- basic_table() %>% - split_cols_by("ARM", show_colcounts = TRUE) %>% - split_cols_by("STRATA1") %>% + lyt2 <- basic_table() |> + split_cols_by("ARM", show_colcounts = TRUE) |> + split_cols_by("STRATA1") |> analyze("AGE") tab2 <- build_table(lyt2, ex_adsl) @@ -222,14 +222,14 @@ test_that("equivalent split funs withs differrent environments dont' block rbind "A_C", "Arms A+C", c("A: Drug X", "C: Combination"), list() ) - l1 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM", split_fun = add_combo_levels(combodf)) %>% + l1 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = add_combo_levels(combodf)) |> analyze("AGE") tab1 <- build_table(l1, DM) - l2 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM", split_fun = add_combo_levels(combodf)) %>% + l2 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = add_combo_levels(combodf)) |> analyze("SEX") tab2 <- build_table(l2, DM) @@ -239,9 +239,9 @@ test_that("equivalent split funs withs differrent environments dont' block rbind }) test_that("cbinding table with counts and with NA counts works", { - tbl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - analyze("AGE") %>% + tbl <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + analyze("AGE") |> build_table(DM) @@ -257,9 +257,9 @@ test_that("cbinding table with counts and with NA counts works", { }) test_that("rbinding 2 objects with different titles/footers removes them", { - tbl_a <- basic_table(title = "Title A", subtitles = "Subtitle A", main_footer = "Footer A", prov_footer = "PF A") %>% + tbl_a <- basic_table(title = "Title A", subtitles = "Subtitle A", main_footer = "Footer A", prov_footer = "PF A") |> build_table(ex_adsl) - tbl_b <- basic_table(title = "Title B", subtitles = "Subtitle B", main_footer = "Footer B", prov_footer = "PF B") %>% + tbl_b <- basic_table(title = "Title B", subtitles = "Subtitle B", main_footer = "Footer B", prov_footer = "PF B") |> build_table(ex_adsl) tbl_ab <- rbind(tbl_a, tbl_b) @@ -272,9 +272,9 @@ test_that("rbinding 2 objects with different titles/footers removes them", { test_that("rbinding objects with only titles/footers for first object keeps them", { tbl_a <- basic_table( title = "Title", subtitles = c("S1", "S2"), main_footer = c("F1", "F2"), prov_footer = c("PF1", "PF2") - ) %>% + ) |> build_table(ex_adsl) - tbl_b <- basic_table() %>% + tbl_b <- basic_table() |> build_table(ex_adsl) tbl_ab <- rbind(tbl_a, rrow("Total xx", ""), tbl_b) @@ -287,11 +287,11 @@ test_that("rbinding objects with only titles/footers for first object keeps them test_that("rbinding objects with identical titles/footers keeps them", { tbl_a <- basic_table( title = "Title", subtitles = c("S1", "S2", "S3"), main_footer = "Footer", prov_footer = c("PF1", "PF2") - ) %>% + ) |> build_table(ex_adsl) tbl_b <- basic_table( title = "Title", subtitles = c("S1", "S2", "S3"), main_footer = "Footer", prov_footer = c("PF1", "PF2") - ) %>% + ) |> build_table(ex_adsl) tbl_ab <- rbind(tbl_a, tbl_b) diff --git a/tests/testthat/test-colby_constructors.R b/tests/testthat/test-colby_constructors.R index 08543d58ad..ca7b417bc9 100644 --- a/tests/testthat/test-colby_constructors.R +++ b/tests/testthat/test-colby_constructors.R @@ -1,7 +1,7 @@ test_that("analyze's var_labels accepts a vector of length 1 consisting of a single NA", { testthat::expect_no_error( - basic_table() %>% - split_cols_by("ARM") %>% + basic_table() |> + split_cols_by("ARM") |> analyze("AGE", var_labels = c(AGE = NA)) ) }) diff --git a/tests/testthat/test-default_split_funs.R b/tests/testthat/test-default_split_funs.R index 46349c8bfa..97d90c0aa5 100644 --- a/tests/testthat/test-default_split_funs.R +++ b/tests/testthat/test-default_split_funs.R @@ -2,12 +2,12 @@ context("Default Split Functions") # Default split functions ------------------------------------------------------ test_that("keep_split_levels(reorder) works correctly", { - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by("COUNTRY", split_fun = keep_split_levels(c("JPN", "USA", "NGA"), reorder = FALSE ) - ) %>% + ) |> summarize_row_groups() # for simplicity tbl <- build_table(lyt, DM) @@ -18,10 +18,10 @@ test_that("keep_split_levels(reorder) works correctly", { ) # reorder = TRUE - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by("COUNTRY", split_fun = keep_split_levels(c("JPN", "USA", "NGA")) - ) %>% + ) |> summarize_row_groups() tbl <- build_table(lyt, DM) @@ -33,10 +33,10 @@ test_that("keep_split_levels(reorder) works correctly", { # Error only during build expect_silent( - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by("COUNTRY", split_fun = keep_split_levels(c("AbsentCountry", "USA", "NGA")) - ) %>% + ) |> summarize_row_groups() ) expect_error(build_table(lyt, DM), "AbsentCountry") @@ -47,20 +47,20 @@ test_that("keep_split_level works also with empty splits", { require(dplyr, quietly = TRUE) # Regression #1010 - iris2 <- iris %>% - mutate(chr_split = as.character(Species)) %>% + iris2 <- iris |> + mutate(chr_split = as.character(Species)) |> mutate(fct_split = factor(rep(1, nrow(iris)), levels = c(1, 2))) - lyt <- basic_table() %>% - split_rows_by("fct_split") %>% - split_rows_by("chr_split", split_fun = keep_split_levels(c("setosa"))) %>% + lyt <- basic_table() |> + split_rows_by("fct_split") |> + split_rows_by("chr_split", split_fun = keep_split_levels(c("setosa"))) |> analyze("Sepal.Length") expect_silent(tbl <- build_table(lyt, iris2)) # Error with character - lyt <- basic_table() %>% - split_rows_by("chr_split", split_fun = keep_split_levels(c("a"))) %>% + lyt <- basic_table() |> + split_rows_by("chr_split", split_fun = keep_split_levels(c("a"))) |> analyze("Sepal.Length") expect_error( @@ -70,8 +70,8 @@ test_that("keep_split_level works also with empty splits", { # Error with factor iris2$chr_split <- as.factor(iris2$chr_split) - lyt <- basic_table() %>% - split_rows_by("chr_split", split_fun = keep_split_levels(c("a"))) %>% + lyt <- basic_table() |> + split_rows_by("chr_split", split_fun = keep_split_levels(c("a"))) |> analyze("Sepal.Length") expect_error( @@ -81,14 +81,14 @@ test_that("keep_split_level works also with empty splits", { }) test_that("reorder_split_levels(drlevels = TRUE) works", { - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( neworder = c("U", "F"), newlabels = c(U = "Uu", `F` = "Female") ) - ) %>% + ) |> summarize_row_groups() tab <- build_table(lyt, DM) @@ -98,14 +98,14 @@ test_that("reorder_split_levels(drlevels = TRUE) works", { ) # Error when not present - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( neworder = c("U", "F", "NotPresent"), newlabels = c(U = "Uu", `F` = "Female") ) - ) %>% + ) |> summarize_row_groups() expect_error( @@ -114,14 +114,14 @@ test_that("reorder_split_levels(drlevels = TRUE) works", { ) # Error when name not present - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( neworder = c("U", "F"), newlabels = c(U = "Uu", Fem = "Female") ) - ) %>% + ) |> summarize_row_groups() expect_error( @@ -130,14 +130,14 @@ test_that("reorder_split_levels(drlevels = TRUE) works", { ) # Error when vector of different lengths - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( neworder = c("U", "F"), newlabels = c("Uu", "Female", "NotPresent") ) - ) %>% + ) |> summarize_row_groups() expect_error( @@ -147,7 +147,7 @@ test_that("reorder_split_levels(drlevels = TRUE) works", { }) test_that("reorder_split_levels(drlevels = FALSE) works", { - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( @@ -155,7 +155,7 @@ test_that("reorder_split_levels(drlevels = FALSE) works", { newlabels = c(U = "Uu", `F` = "Female"), drlevels = FALSE ) - ) %>% + ) |> summarize_row_groups() tab <- build_table(lyt, DM) @@ -165,7 +165,7 @@ test_that("reorder_split_levels(drlevels = FALSE) works", { ) # Error when newlabels too many - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( @@ -173,7 +173,7 @@ test_that("reorder_split_levels(drlevels = FALSE) works", { newlabels = c(U = "Uu", `F` = "Female", "ThisNotGood"), drlevels = FALSE ) - ) %>% + ) |> summarize_row_groups() expect_error( @@ -182,7 +182,7 @@ test_that("reorder_split_levels(drlevels = FALSE) works", { ) # Error when newlabels have empty "" names (but some names) - lyt <- basic_table() %>% + lyt <- basic_table() |> split_rows_by( "SEX", split_fun = reorder_split_levels( @@ -190,7 +190,7 @@ test_that("reorder_split_levels(drlevels = FALSE) works", { newlabels = c(U = "Uu", "Female"), drlevels = FALSE ) - ) %>% + ) |> summarize_row_groups() expect_error( @@ -201,15 +201,15 @@ test_that("reorder_split_levels(drlevels = FALSE) works", { ## regression test (https://github.com/insightsengineering/rtables/issues/191) test_that("regression for reorder_split_levels(newlabels)", { - lyt <- basic_table() %>% - split_cols_by("ARM") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> split_rows_by( "COUNTRY", split_fun = reorder_split_levels( neworder = c("CAN", "PAK", "BRA"), newlabels = c(CAN = "Canada", PAK = "Pakistan", BRA = "Brazil") ) - ) %>% + ) |> analyze("AGE") tab <- build_table(lyt, ex_adsl) expect_identical( @@ -221,8 +221,8 @@ test_that("regression for reorder_split_levels(newlabels)", { test_that("remove_split_levels works as expected with factor variables", { my_split_fun <- remove_split_levels(excl = "ASIAN") - l <- basic_table() %>% - split_rows_by("RACE", split_fun = my_split_fun) %>% + l <- basic_table() |> + split_rows_by("RACE", split_fun = my_split_fun) |> summarize_row_groups() tab <- build_table(l, DM) @@ -230,8 +230,8 @@ test_that("remove_split_levels works as expected with factor variables", { expect_false("ASIAN" %in% row.names(tab)) # No error if not present - l <- basic_table() %>% - split_rows_by("RACE", split_fun = remove_split_levels("a")) %>% + l <- basic_table() |> + split_rows_by("RACE", split_fun = remove_split_levels("a")) |> summarize_row_groups() expect_silent(tab <- build_table(l, DM)) @@ -240,9 +240,9 @@ test_that("remove_split_levels works as expected with factor variables", { test_that("remove_split_levels works as expected with character variables", { my_split_fun <- remove_split_levels(excl = "ASIAN") - l <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE", split_fun = my_split_fun) %>% + l <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE", split_fun = my_split_fun) |> summarize_row_groups() DM2 <- DM @@ -255,9 +255,9 @@ test_that("remove_split_levels works as expected with character variables", { test_that("drop_and_remove_levels works as expected when dropping not appearing levels", { my_split_fun <- drop_and_remove_levels(excl = "ASIAN") - l <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE", split_fun = my_split_fun) %>% + l <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE", split_fun = my_split_fun) |> summarize_row_groups() tab <- build_table(l, DM) @@ -271,9 +271,9 @@ test_that("drop_and_remove_levels works as expected when dropping not appearing test_that("drop_and_remove_levels also works with character variables", { my_split_fun <- drop_and_remove_levels(excl = "ASIAN") - l <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE", split_fun = my_split_fun) %>% + l <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE", split_fun = my_split_fun) |> summarize_row_groups() DM2 <- DM @@ -297,9 +297,9 @@ test_that("trim_levels_to_map split function works", { stringsAsFactors = FALSE ) - lyt <- basic_table() %>% - split_rows_by("LBCAT") %>% - split_rows_by("PARAMCD", split_fun = trim_levels_to_map(map = map)) %>% + lyt <- basic_table() |> + split_rows_by("LBCAT") |> + split_rows_by("PARAMCD", split_fun = trim_levels_to_map(map = map)) |> analyze("ANRIND") tbl1 <- build_table(lyt, ex_adlb) @@ -321,16 +321,16 @@ test_that("trim_levels_to_map split function works", { "C: Combination", "NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER" ) - lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("RACE", split_fun = trim_levels_to_map(map = map2)) %>% + lyt2 <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("RACE", split_fun = trim_levels_to_map(map = map2)) |> analyze("AGE") expect_error(build_table(lyt2, DM), regexp = "map does not allow") - lyt3 <- basic_table() %>% - split_cols_by("ARM", split_fun = trim_levels_to_map(map = map2)) %>% - split_cols_by("RACE", split_fun = trim_levels_to_map(map = map2)) %>% + lyt3 <- basic_table() |> + split_cols_by("ARM", split_fun = trim_levels_to_map(map = map2)) |> + split_cols_by("RACE", split_fun = trim_levels_to_map(map = map2)) |> analyze("AGE") tbl3 <- build_table(lyt3, DM) @@ -363,10 +363,10 @@ test_that("trim_levels_to_map split function works", { stringsAsFactors = FALSE ) - lyt4 <- basic_table() %>% - split_rows_by("LBCAT", split_fun = trim_levels_to_map(map = map)) %>% - split_rows_by("PARAM", split_fun = trim_levels_to_map(map = map)) %>% - split_rows_by("VISIT", split_fun = trim_levels_to_map(map = map)) %>% + lyt4 <- basic_table() |> + split_rows_by("LBCAT", split_fun = trim_levels_to_map(map = map)) |> + split_rows_by("PARAM", split_fun = trim_levels_to_map(map = map)) |> + split_rows_by("VISIT", split_fun = trim_levels_to_map(map = map)) |> analyze("ABN") tbl4 <- build_table(lyt4, df = data) @@ -394,9 +394,9 @@ test_that("trim_levels_in_group works", { ) ## This works - tbl1 <- basic_table() %>% - split_rows_by("l1", split_fun = trim_levels_in_group("l2")) %>% - analyze("l2") %>% + tbl1 <- basic_table() |> + split_rows_by("l1", split_fun = trim_levels_in_group("l2")) |> + analyze("l2") |> build_table(dat1) @@ -406,9 +406,9 @@ test_that("trim_levels_in_group works", { ) ## This previously gave an error because trim_levels_in_group did not drop the empty "l1" levels - tbl2 <- basic_table() %>% - split_rows_by("l1", split_fun = trim_levels_in_group("l2")) %>% - analyze("l2") %>% + tbl2 <- basic_table() |> + split_rows_by("l1", split_fun = trim_levels_in_group("l2")) |> + analyze("l2") |> build_table(dat2) expect_identical(nrow(tbl1), 6L) diff --git a/tests/testthat/test-deprecated.R b/tests/testthat/test-deprecated.R index 37b4f81cde..bf2910a97d 100644 --- a/tests/testthat/test-deprecated.R +++ b/tests/testthat/test-deprecated.R @@ -3,15 +3,15 @@ context("deprecated functionality") test_that("deprecated things are still there and work kinda", { lifecycle::expect_deprecated(lyt11 <- split_cols_by(lyt = NULL, "ARM")) - expect_identical(lyt11, basic_table() %>% split_cols_by("ARM")) + expect_identical(lyt11, basic_table() |> split_cols_by("ARM")) lifecycle::expect_deprecated(lyt22 <- split_rows_by(lyt = NULL, "ARM")) - expect_identical(lyt22, basic_table() %>% split_rows_by("ARM")) + expect_identical(lyt22, basic_table() |> split_rows_by("ARM")) }) test_that("deprecated insert_rrow still currently works", { - tbl <- basic_table() %>% - split_cols_by("Species") %>% - analyze("Sepal.Length") %>% + tbl <- basic_table() |> + split_cols_by("Species") |> + analyze("Sepal.Length") |> build_table(iris) lifecycle::expect_deprecated(res1 <- insert_rrow(tbl, rrow("Hello World"))) @@ -24,10 +24,10 @@ test_that("deprecated insert_rrow still currently works", { mf2 <- matrix_form(res2) expect_identical(mf2$strings[3, , drop = TRUE], c("Hello World", "", "", "")) - tbl2 <- basic_table() %>% - split_cols_by("Species") %>% - split_rows_by("Species") %>% - analyze("Sepal.Length") %>% + tbl2 <- basic_table() |> + split_cols_by("Species") |> + split_rows_by("Species") |> + analyze("Sepal.Length") |> build_table(iris) ## for coverage res3 <- insert_rrow(tbl2, rrow("Hello World")) @@ -51,13 +51,13 @@ test_that("deprecated insert_rrow still currently works", { }) test_that("add_colcounts works", { - tbl1 <- basic_table() %>% - add_colcounts() %>% - analyze("AGE") %>% + tbl1 <- basic_table() |> + add_colcounts() |> + analyze("AGE") |> build_table(DM) - tbl2 <- basic_table(show_colcounts = TRUE) %>% - analyze("AGE") %>% + tbl2 <- basic_table(show_colcounts = TRUE) |> + analyze("AGE") |> build_table(DM) expect_true(identical(tbl1, tbl2)) @@ -65,16 +65,16 @@ test_that("add_colcounts works", { test_that("add_colcounts format argument works", { # 2d count (%) format works - tbl1 <- basic_table() %>% - add_colcounts(format = "xx (xx%)") %>% - split_cols_by("ARM") %>% + tbl1 <- basic_table() |> + add_colcounts(format = "xx (xx%)") |> + split_cols_by("ARM") |> build_table(DM) mf_tbl1_colcounts <- matrix_form(tbl1)$strings[2, ] expect_identical(mf_tbl1_colcounts, c("", "121 (100%)", "106 (100%)", "129 (100%)")) # correct error message for 2d format without % - lyt <- basic_table() %>% - add_colcounts(format = "xx (xx)") %>% + lyt <- basic_table() |> + add_colcounts(format = "xx (xx)") |> split_cols_by("ARM") expect_error( matrix_form(build_table(lyt, DM)), @@ -85,8 +85,8 @@ test_that("add_colcounts format argument works", { ) # correct error message for 3d colcount format - lyt <- basic_table() %>% - add_colcounts(format = "xx.x (xx.x - xx.x)") %>% + lyt <- basic_table() |> + add_colcounts(format = "xx.x (xx.x - xx.x)") |> split_cols_by("ARM") expect_error(matrix_form(build_table(lyt, DM)), "3d formats are not supported for column counts.") }) diff --git a/tests/testthat/test-exporters.R b/tests/testthat/test-exporters.R index 600e6e26fc..75f7d86070 100644 --- a/tests/testthat/test-exporters.R +++ b/tests/testthat/test-exporters.R @@ -1,8 +1,8 @@ context("Exporting to txt, pdf, rtf, and docx") test_that("export_as_txt works with and without pagination", { - lyt <- basic_table() %>% - split_cols_by("ARM") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR2", "COUNTRY")) tbl <- build_table(lyt, ex_adsl) @@ -210,8 +210,8 @@ test_that("export_as_pdf works", { # test_that("exporting pdfs gives the correct values", { # if (check_pdf) { -# lyt <- basic_table(title = " ") %>% -# split_rows_by("SEX", page_by = TRUE) %>% +# lyt <- basic_table(title = " ") |> +# split_rows_by("SEX", page_by = TRUE) |> # analyze("AGE") # # # Building the table @@ -250,9 +250,9 @@ test_that("exporting pdf does the inset", { ## https://github.com/insightsengineering/rtables/issues/308 test_that("path_enriched_df works for tables with a column that has all length 1 elements", { - my_table <- basic_table() %>% - split_rows_by("Species") %>% - analyze("Petal.Length") %>% + my_table <- basic_table() |> + split_rows_by("Species") |> + analyze("Petal.Length") |> build_table(df = iris) mydf <- path_enriched_df(my_table) expect_identical(dim(mydf), c(3L, 2L)) diff --git a/tests/testthat/test-formatting.R b/tests/testthat/test-formatting.R index 11d3edf722..d781df4aa6 100644 --- a/tests/testthat/test-formatting.R +++ b/tests/testthat/test-formatting.R @@ -3,8 +3,8 @@ context("value formatting") test_that("sprintf_format works correctly", { myfun <- sprintf_format("hi there %1.4f") - lyt <- basic_table() %>% - split_cols_by("Species") %>% + lyt <- basic_table() |> + split_cols_by("Species") |> analyze("Sepal.Width", afun = mean, format = myfun) tbl <- build_table(lyt, iris) @@ -120,10 +120,10 @@ test_that("format_na_str functionality works in get_formatted_cells (i.e. printi .format_na_strs = c(mean = "Ridiculous") ) - l <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("COUNTRY", split_fun = drop_split_levels) %>% - summarize_row_groups(label_fstr = "%s (n)") %>% + l <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("COUNTRY", split_fun = drop_split_levels) |> + summarize_row_groups(label_fstr = "%s (n)") |> analyze("AGE", afun = a_summary3, format = "xx.xx") tbl <- suppressWarnings(build_table(l, DM2)) @@ -139,8 +139,8 @@ test_that("format and na_str inheritance", { require(dplyr, quietly = TRUE) # Test data - DM2 <- DM %>% - filter(ARM != levels(DM$ARM)[3]) %>% + DM2 <- DM |> + filter(ARM != levels(DM$ARM)[3]) |> mutate(ARM = as.factor(as.character(ARM))) DM2$AGE[1] <- NA # Adding one NA @@ -158,9 +158,9 @@ test_that("format and na_str inheritance", { } # Main builder - tbl <- basic_table() %>% - split_cols_by("ARM") %>% - analyze("AGE", weird_afun, format = "xx.xx", na_str = "lol") %>% + tbl <- basic_table() |> + split_cols_by("ARM") |> + analyze("AGE", weird_afun, format = "xx.xx", na_str = "lol") |> build_table(DM2) # Get the ASCII table @@ -170,17 +170,17 @@ test_that("format and na_str inheritance", { require(dplyr, quietly = TRUE) # Expected data-set is built with dplyr - expected <- DM2 %>% - dplyr::group_by(ARM) %>% + expected <- DM2 |> + dplyr::group_by(ARM) |> summarise( m_age = format_value(mean(AGE, na.rm = TRUE), format = "xx.x"), me_age = format_value(median(AGE, na.rm = TRUE), format = "xx.xx"), m_range = paste(sapply(range(AGE, na.rm = TRUE), format_value, format = "xx.x"), collapse = " - ") - ) %>% - mutate(b = "lol", c = "what", d = "bah - 2.0", e = "lol - 2.0") %>% - select(m_age, me_age, b, c, m_range, d, e) %>% - mutate_all(as.character) %>% - t() %>% + ) |> + mutate(b = "lol", c = "what", d = "bah - 2.0", e = "lol - 2.0") |> + select(m_age, me_age, b, c, m_range, d, e) |> + mutate_all(as.character) |> + t() |> as.matrix() dimnames(expected) <- NULL # Fixing attributes diff --git a/tests/testthat/test-header-footer.R b/tests/testthat/test-header-footer.R index 93caea3fbc..a7f8ff70c1 100644 --- a/tests/testthat/test-header-footer.R +++ b/tests/testthat/test-header-footer.R @@ -12,8 +12,8 @@ test_that("referential footnotes work", { lyt <- basic_table( title = "Title says Whaaaat", subtitles = "Oh, ok.", main_footer = "ha HA! Footer!" - ) %>% - split_cols_by("ARM") %>% + ) |> + split_cols_by("ARM") |> analyze("AGE", afun = analysisfun) result <- build_table(lyt, ex_adsl) @@ -52,8 +52,8 @@ test_that("referential footnotes work", { .formats = list(mean = "xx.x", range = "xx - xx") ) } - lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% + lyt2 <- basic_table() |> + split_cols_by("ARM") |> analyze("AGE", afun = analysisfun2, extra_args = list(cutoff = mean(ex_adsl$AGE))) tbl <- build_table(lyt2, ex_adsl) rdf2 <- make_row_df(tbl) @@ -70,10 +70,10 @@ test_that("post-processing addition of referential footnotes works", { "AMERICAN INDIAN OR ALASKA NATIVE", "MULTIPLE" ) - l1 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE", split_fun = keep_split_levels(race_levels)) %>% - summarize_row_groups() %>% + l1 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE", split_fun = keep_split_levels(race_levels)) |> + summarize_row_groups() |> analyze("AGE", mean, format = "xx.x") @@ -141,9 +141,9 @@ test_that("post-processing addition of referential footnotes works", { - l2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE", split_fun = keep_split_levels(race_levels)) %>% + l2 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE", split_fun = keep_split_levels(race_levels)) |> analyze("AGE", mean, format = "xx.x") tb2 <- build_table(l2, DM) diff --git a/tests/testthat/test-indent-mod.R b/tests/testthat/test-indent-mod.R index 7e45e3dc02..57c34b4d2f 100644 --- a/tests/testthat/test-indent-mod.R +++ b/tests/testthat/test-indent-mod.R @@ -1,8 +1,8 @@ context("Indent modifiers") test_that("indent modifiers propogated from analyze calls properly", { - lyt <- basic_table() %>% - analyze("Sepal.Width", afun = mean, show_labels = "visible") %>% + lyt <- basic_table() |> + analyze("Sepal.Width", afun = mean, show_labels = "visible") |> analyze("Sepal.Width", afun = median, show_labels = "hidden", indent_mod = 2L, table_names = "SecondAge" @@ -15,13 +15,13 @@ test_that("indent modifiers propogated from analyze calls properly", { test_that("indents are correct in make_row_df", { - l1 <- basic_table() %>% - split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label") %>% - summarize_row_groups("RACE", label_fstr = "%s (n)") %>% + l1 <- basic_table() |> + split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label") |> + summarize_row_groups("RACE", label_fstr = "%s (n)") |> split_rows_by("FACTOR2", "Factor2", split_fun = remove_split_levels("C"), labels_var = "fac2_label" - ) %>% + ) |> analyze( "AGE", "Age Analysis", afun = function(x) list(mean = mean(x), median = median(x)), @@ -35,7 +35,7 @@ test_that("indents are correct in make_row_df", { pgdf1$indent ) - l2 <- l1 %>% analyze("AGE", + l2 <- l1 |> analyze("AGE", var_labels = "Age Analysis Redux", table_names = "AgeRedux", afun = range, format = "xx - xx" ) @@ -48,14 +48,14 @@ test_that("indents are correct in make_row_df", { ) - l3 <- basic_table() %>% - split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label") %>% - summarize_row_groups("RACE", label_fstr = "%s (n)") %>% + l3 <- basic_table() |> + split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label") |> + summarize_row_groups("RACE", label_fstr = "%s (n)") |> split_rows_by("FACTOR2", "Factor2", split_fun = remove_split_levels("C"), labels_var = "fac2_label", indent_mod = 0 - ) %>% + ) |> analyze( "AGE", "Age Analysis", afun = function(x) list(mean = mean(x), median = median(x)), @@ -70,14 +70,14 @@ test_that("indents are correct in make_row_df", { pgdf3$indent ) - l4 <- basic_table() %>% - split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label") %>% - summarize_row_groups("RACE", label_fstr = "%s (n)") %>% + l4 <- basic_table() |> + split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label") |> + summarize_row_groups("RACE", label_fstr = "%s (n)") |> split_rows_by("FACTOR2", "Factor2", split_fun = remove_split_levels("C"), labels_var = "fac2_label", indent_mod = -1 - ) %>% + ) |> analyze( "AGE", "Age Analysis", afun = function(x) list(mean = mean(x), median = median(x)), @@ -91,14 +91,14 @@ test_that("indents are correct in make_row_df", { pagdf4$indent ) - l5 <- basic_table() %>% - split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label", indent_mod = 2) %>% - summarize_row_groups("RACE", label_fstr = "%s (n)") %>% + l5 <- basic_table() |> + split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label", indent_mod = 2) |> + summarize_row_groups("RACE", label_fstr = "%s (n)") |> split_rows_by("FACTOR2", "Factor2", split_fun = remove_split_levels("C"), labels_var = "fac2_label", indent_mod = -2 - ) %>% + ) |> analyze( "AGE", "Age Analysis", afun = function(x) list(mean = mean(x), median = median(x)), @@ -112,17 +112,17 @@ test_that("indents are correct in make_row_df", { pgdf5$indent ) - l6 <- basic_table() %>% + l6 <- basic_table() |> split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label", indent_mod = 0, label_pos = "visible" - ) %>% - summarize_row_groups("RACE", label_fstr = "%s (n)") %>% + ) |> + summarize_row_groups("RACE", label_fstr = "%s (n)") |> split_rows_by("FACTOR2", "Factor2", split_fun = remove_split_levels("C"), labels_var = "fac2_label", indent_mod = 0 - ) %>% + ) |> analyze( "AGE", "Age Analysis", afun = function(x) list(mean = mean(x), median = median(x)), @@ -142,17 +142,17 @@ test_that("indents are correct in make_row_df", { ## children inherit table idnent mod, NOT content indent_mod, when thsoe two ## values are different. - l7 <- basic_table() %>% + l7 <- basic_table() |> split_rows_by("RACE", "Ethnicity", labels_var = "ethn_label", indent_mod = 2, label_pos = "visible" - ) %>% - summarize_row_groups("RACE", label_fstr = "%s (n)", indent_mod = -1) %>% + ) |> + summarize_row_groups("RACE", label_fstr = "%s (n)", indent_mod = -1) |> split_rows_by("FACTOR2", "Factor2", split_fun = remove_split_levels("C"), labels_var = "fac2_label", indent_mod = 0 - ) %>% + ) |> analyze( "AGE", "Age Analysis", afun = function(x) list(mean = mean(x), median = median(x)), @@ -168,11 +168,11 @@ test_that("indents are correct in make_row_df", { }) test_that("getters and setters work", { - t0 <- basic_table() %>% - summarize_row_groups("STUDYID", label_fstr = "overall summary") %>% - split_rows_by("AEBODSYS", child_labels = "visible") %>% - summarize_row_groups("STUDYID", label_fstr = "subgroup summary") %>% - analyze("AGE") %>% + t0 <- basic_table() |> + summarize_row_groups("STUDYID", label_fstr = "overall summary") |> + split_rows_by("AEBODSYS", child_labels = "visible") |> + summarize_row_groups("STUDYID", label_fstr = "subgroup summary") |> + analyze("AGE") |> build_table(ex_adae) expect_equal(indent_mod(t0), 0) @@ -215,18 +215,18 @@ test_that("getters and setters work", { test_that("clear_indent_mods works as desired", { - lytm <- basic_table() %>% - summarize_row_groups("STUDYID", label_fstr = "overall summary", indent_mod = 1L) %>% - split_rows_by("AEBODSYS", child_labels = "visible") %>% - summarize_row_groups("STUDYID", label_fstr = "subgroup summary") %>% + lytm <- basic_table() |> + summarize_row_groups("STUDYID", label_fstr = "overall summary", indent_mod = 1L) |> + split_rows_by("AEBODSYS", child_labels = "visible") |> + summarize_row_groups("STUDYID", label_fstr = "subgroup summary") |> analyze("AGE", indent_mod = -1L) tm <- build_table(lytm, ex_adae) - t0 <- basic_table() %>% - summarize_row_groups("STUDYID", label_fstr = "overall summary") %>% - split_rows_by("AEBODSYS", child_labels = "visible") %>% - summarize_row_groups("STUDYID", label_fstr = "subgroup summary") %>% - analyze("AGE") %>% + t0 <- basic_table() |> + summarize_row_groups("STUDYID", label_fstr = "overall summary") |> + split_rows_by("AEBODSYS", child_labels = "visible") |> + summarize_row_groups("STUDYID", label_fstr = "subgroup summary") |> + analyze("AGE") |> build_table(ex_adae) expect_identical( diff --git a/tests/testthat/test-make-afun.R b/tests/testthat/test-make-afun.R index bae3620804..5f528d94bd 100644 --- a/tests/testthat/test-make-afun.R +++ b/tests/testthat/test-make-afun.R @@ -218,8 +218,8 @@ test_that("make_afun .indent_mods argument works", { c(nrow_df = 2L, .N_col = 1L, a = 1L, b = 2L) ) - tbl <- basic_table() %>% - analyze("Sepal.Length", a_imod) %>% + tbl <- basic_table() |> + analyze("Sepal.Length", a_imod) |> build_table(iris) rows <- tree_children(tbl) expect_identical( @@ -286,11 +286,11 @@ test_that("make_afun+build_table integration tests", { min_max = "xx.xx - xx.xx" ) ) - tbl <- basic_table() %>% + tbl <- basic_table() |> analyze( "Sepal.Length", afun = a_summary - ) %>% + ) |> build_table(iris) expect_identical( @@ -302,12 +302,12 @@ test_that("make_afun+build_table integration tests", { ) ) - tbl2 <- basic_table() %>% - split_cols_by("Species") %>% + tbl2 <- basic_table() |> + split_cols_by("Species") |> analyze( "Sepal.Length", afun = a_summary - ) %>% + ) |> build_table(iris) expect_identical( @@ -343,11 +343,11 @@ test_that("make_afun+build_table integration tests", { min_max = "Range" ) ) - tbl3 <- basic_table() %>% + tbl3 <- basic_table() |> analyze( "Sepal.Length", afun = a_summary2 - ) %>% + ) |> build_table(iris) expect_identical( @@ -359,12 +359,12 @@ test_that("make_afun+build_table integration tests", { ) ) - tbl4 <- basic_table() %>% - split_cols_by("Species") %>% + tbl4 <- basic_table() |> + split_cols_by("Species") |> analyze( "Sepal.Length", afun = a_summary2 - ) %>% + ) |> build_table(iris) expect_identical( @@ -383,11 +383,11 @@ test_that("make_afun+build_table integration tests", { a_summary, .labels = c(min_max = "New Range") ) - tbl5 <- basic_table() %>% - split_cols_by("Species") %>% + tbl5 <- basic_table() |> + split_cols_by("Species") |> analyze("Sepal.Length", afun = a_function3 - ) %>% + ) |> build_table(iris) expect_identical( @@ -403,11 +403,11 @@ test_that("make_afun+build_table integration tests", { a_summary2, .labels = c(min_max = "New Range") ) - tbl5 <- basic_table() %>% - split_cols_by("Species") %>% + tbl5 <- basic_table() |> + split_cols_by("Species") |> analyze("Sepal.Length", afun = a_function4 - ) %>% + ) |> build_table(iris) expect_identical( diff --git a/tests/testthat/test-matrix_form.R b/tests/testthat/test-matrix_form.R index 44bb3f6c3d..43df932115 100644 --- a/tests/testthat/test-matrix_form.R +++ b/tests/testthat/test-matrix_form.R @@ -3,8 +3,8 @@ context("matrix_form works") test_that("matrix_form works with indent_rownames = FALSE", { # Discovered thanks to more stringent indentation checks. See #844 for when it # surfaced. Cause: make_row_df does not update mf_rinfo indentation if indent_rownames = FALSE - lyt <- basic_table() %>% - split_rows_by("ARM") %>% + lyt <- basic_table() |> + split_rows_by("ARM") |> analyze("AGE") tbl <- build_table(lyt, ex_adsl) mf <- matrix_form(tbl, indent_rownames = FALSE) diff --git a/tests/testthat/test-pagination.R b/tests/testthat/test-pagination.R index 4a5e773b76..3479696041 100644 --- a/tests/testthat/test-pagination.R +++ b/tests/testthat/test-pagination.R @@ -2,8 +2,8 @@ context("Pagination") test_that("Page by splitting works", { - lyt <- basic_table(title = "big title") %>% - split_rows_by("SEX", page_by = TRUE) %>% + lyt <- basic_table(title = "big title") |> + split_rows_by("SEX", page_by = TRUE) |> analyze("AGE") tt <- build_table(lyt, DM) @@ -24,9 +24,9 @@ test_that("Page by splitting works", { expect_error( { - basic_table(title = "big title") %>% - analyze("AGE") %>% - split_rows_by("SEX", page_by = TRUE) %>% + basic_table(title = "big title") |> + analyze("AGE") |> + split_rows_by("SEX", page_by = TRUE) |> analyze("AGE") }, "page_by splits cannot have top-level siblings" @@ -34,9 +34,9 @@ test_that("Page by splitting works", { expect_error( { - basic_table() %>% - split_rows_by("SEX") %>% - split_rows_by("ARM", page_by = TRUE) %>% + basic_table() |> + split_rows_by("SEX") |> + split_rows_by("ARM", page_by = TRUE) |> analyze("AGE") }, "page_by splits cannot be nested within non-page_by splits" @@ -47,12 +47,12 @@ test_that("Page by splitting works", { subtitles = "subtitle", main_footer = "main footer", prov_footer = "provenance footer" - ) %>% - split_cols_by("ARM") %>% - split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) %>% - split_rows_by("STRATA1", split_fun = keep_split_levels(c("A", "B")), page_by = TRUE, page_prefix = "Stratum") %>% - split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) %>% - summarize_row_groups() %>% + ) |> + split_cols_by("ARM") |> + split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) |> + split_rows_by("STRATA1", split_fun = keep_split_levels(c("A", "B")), page_by = TRUE, page_prefix = "Stratum") |> + split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) |> + summarize_row_groups() |> analyze("AGE", afun = function(x, ...) { in_rows( "mean (sd)" = rcell( @@ -76,36 +76,36 @@ test_that("Page by splitting works", { test_that("export_as_txt prints split level header correctly when using page_by", { # single level in page_by split - tbl <- basic_table() %>% + tbl <- basic_table() |> split_rows_by("PARAMCD", labels_var = "PARAMCD", split_label = "aaa", label_pos = "topleft", split_fun = drop_split_levels, page_by = TRUE - ) %>% + ) |> split_rows_by("AVISIT", label_pos = "topleft", split_fun = keep_split_levels("SCREENING") - ) %>% - analyze("AVAL") %>% + ) |> + analyze("AVAL") |> build_table(ex_adlb[ex_adlb$PARAMCD == "ALT", ]) - tbl_txt <- tbl %>% export_as_txt(lpp = 100) + tbl_txt <- tbl |> export_as_txt(lpp = 100) expect_true(grepl("^\naaa: ALT", tbl_txt)) # multiple levels in page_by split - tbl <- basic_table() %>% + tbl <- basic_table() |> split_rows_by("PARAMCD", labels_var = "PARAMCD", split_label = "aaa", label_pos = "topleft", split_fun = drop_split_levels, page_by = TRUE - ) %>% + ) |> split_rows_by("AVISIT", label_pos = "topleft", split_fun = keep_split_levels("SCREENING") - ) %>% - analyze("AVAL") %>% + ) |> + analyze("AVAL") |> build_table(ex_adlb[ex_adlb$PARAMCD != "IGA", ]) - tbl_txt <- tbl %>% export_as_txt(lpp = 100) + tbl_txt <- tbl |> export_as_txt(lpp = 100) expect_true(grepl("^\naaa: ALT", tbl_txt)) expect_true(grepl("\naaa: CRP", tbl_txt)) @@ -116,8 +116,8 @@ test_that("vertical and horizontal pagination work", { arm = factor(c("a", "b", "c", "d", "e", "f")), var1 = 6 ) - simple_lyt <- basic_table() %>% - split_cols_by("arm") %>% + simple_lyt <- basic_table() |> + split_cols_by("arm") |> analyze("var1", function(x, ...) { in_rows( .list = replicate(30, list(1234)), @@ -244,7 +244,7 @@ test_that("vertical and horizontal pagination work", { - lyt2 <- basic_table() %>% + lyt2 <- basic_table() |> analyze( "mpg", function(x) in_rows(.list = setNames(as.list(x), as.character(seq_along(x)))) @@ -411,9 +411,9 @@ test_that("cell and column wrapping works in pagination", { }) test_that("Pagination works with section dividers", { - lyt <- basic_table(title = "big title") %>% - split_rows_by("SEX", section_div = "~") %>% - split_rows_by("ARM") %>% + lyt <- basic_table(title = "big title") |> + split_rows_by("SEX", section_div = "~") |> + split_rows_by("ARM") |> analyze("AGE") tt <- build_table(lyt, DM) @@ -445,7 +445,7 @@ test_that("Pagination works with section dividers", { }) test_that("Pagination works with non-default min_siblings", { - lyt <- basic_table() %>% + lyt <- basic_table() |> analyze("RACE") tt <- build_table(lyt, DM) @@ -463,8 +463,8 @@ test_that("Pagination works with non-default min_siblings", { }) test_that("Pagination works with wrapped titles/footers", { - lyt <- basic_table() %>% - split_cols_by("SEX") %>% + lyt <- basic_table() |> + split_cols_by("SEX") |> analyze("RACE") tt <- build_table(lyt, DM) @@ -513,12 +513,12 @@ test_that("Pagination works with referential footnotes", { subtitles = "subtitle", main_footer = "main footer", prov_footer = "provenance footer" - ) %>% - split_cols_by("ARM") %>% - split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) %>% - split_rows_by("STRATA1", split_fun = keep_split_levels(c("A", "B")), page_by = TRUE, page_prefix = "Stratum") %>% - split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) %>% - summarize_row_groups() %>% + ) |> + split_cols_by("ARM") |> + split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) |> + split_rows_by("STRATA1", split_fun = keep_split_levels(c("A", "B")), page_by = TRUE, page_prefix = "Stratum") |> + split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) |> + summarize_row_groups() |> analyze("AGE", afun = function(x, ...) { in_rows( "mean (sd)" = rcell( diff --git a/tests/testthat/test-regressions.R b/tests/testthat/test-regressions.R index 7d2799d6b2..8bbf97a400 100644 --- a/tests/testthat/test-regressions.R +++ b/tests/testthat/test-regressions.R @@ -29,15 +29,15 @@ test_that("inclNAs argument works as expected", { RSP = c(TRUE, FALSE, NA, TRUE), ARM = factor(c("A", "A", "B", "B")) ) - tbl1 <- basic_table() %>% - split_cols_by("ARM") %>% - analyze(vars = "RSP", inclNAs = FALSE) %>% + tbl1 <- basic_table() |> + split_cols_by("ARM") |> + analyze(vars = "RSP", inclNAs = FALSE) |> build_table(df = tinydat) expect_equal(tbl1[1, 2, drop = TRUE], 1) - tbl2 <- basic_table() %>% - split_cols_by("ARM") %>% - analyze(vars = "RSP", inclNAs = TRUE) %>% + tbl2 <- basic_table() |> + split_cols_by("ARM") |> + analyze(vars = "RSP", inclNAs = TRUE) |> build_table(df = tinydat) expect_true(is.na(tbl2[1, 2, drop = TRUE])) @@ -80,10 +80,10 @@ test_that("head/tail work", { }) test_that("sort does not clobber top-level siblings", { - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - analyze("AGE") %>% - split_rows_by("SEX") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> + analyze("AGE") |> + split_rows_by("SEX") |> analyze("AGE", function(x) in_rows(mean = mean(x), "mean+5" = mean(x) + 5)) tbl <- build_table(lyt, rawdat) @@ -96,16 +96,16 @@ test_that("sort does not clobber top-level siblings", { test_that("repeated multi-var analyzes work as expected", { - works <- basic_table() %>% - split_cols_by("ARM") %>% - analyze(c("SEX", "RACE", "STRATA1"), afun = list_wrap_x(table)) %>% - analyze("COUNTRY", afun = list_wrap_x(table)) %>% + works <- basic_table() |> + split_cols_by("ARM") |> + analyze(c("SEX", "RACE", "STRATA1"), afun = list_wrap_x(table)) |> + analyze("COUNTRY", afun = list_wrap_x(table)) |> build_table(DM) - fails <- basic_table() %>% - split_cols_by("ARM") %>% - analyze(c("SEX", "RACE"), afun = list_wrap_x(table)) %>% - analyze(c("STRATA1", "COUNTRY"), afun = list_wrap_x(table)) %>% + fails <- basic_table() |> + split_cols_by("ARM") |> + analyze(c("SEX", "RACE"), afun = list_wrap_x(table)) |> + analyze(c("STRATA1", "COUNTRY"), afun = list_wrap_x(table)) |> build_table(DM) expect_identical(works, fails) @@ -113,18 +113,18 @@ test_that("repeated multi-var analyzes work as expected", { test_that("summarize_row_groups after analyze call(s) work", { - lyt1 <- basic_table() %>% - analyze("SEX") %>% - split_rows_by("SEX") %>% + lyt1 <- basic_table() |> + analyze("SEX") |> + split_rows_by("SEX") |> analyze("SEX") tbl1 <- build_table(lyt1, DM) expect_equal(dim(tbl1), c(24, 1)) ## further regression when we have multiple analyze calls - lyt2 <- basic_table() %>% - analyze("SEX") %>% - analyze("STRATA1") %>% - split_rows_by("SEX") %>% + lyt2 <- basic_table() |> + analyze("SEX") |> + analyze("STRATA1") |> + split_rows_by("SEX") |> analyze("SEX") tbl2 <- build_table(lyt2, DM) expect_equal(dim(tbl2), c(29, 1)) @@ -132,7 +132,7 @@ test_that("summarize_row_groups after analyze call(s) work", { test_that("summarize_row_groups at top level works", { - lyt <- basic_table() %>% + lyt <- basic_table() |> summarize_row_groups("SEX") tbl <- build_table(lyt, DM) @@ -205,9 +205,9 @@ test_that("cell-level formats are retained when column subsetting", { }) test_that("row subsetting works on table with only content rows", { - l <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE") %>% + l <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE") |> summarize_row_groups() tab <- build_table(l, DM) rw <- tab[1, ] @@ -247,9 +247,9 @@ test_that("calls to make_afun within loop work correctly", { lyt } - tab <- basic_table() %>% - split_cols_by("ARM") %>% - dummy_layout(vv = c("BMRKR1", "AGE")) %>% + tab <- basic_table() |> + split_cols_by("ARM") |> + dummy_layout(vv = c("BMRKR1", "AGE")) |> build_table(DM) expect_identical( @@ -266,18 +266,18 @@ test_that("keeping non-existent levels doesn't break internal machinery but erro sfun <- keep_split_levels("ABC") - lyt <- basic_table() %>% - analyze("AGE") %>% - split_rows_by("COUNTRY", split_fun = sfun) %>% - summarize_row_groups() %>% + lyt <- basic_table() |> + analyze("AGE") |> + split_rows_by("COUNTRY", split_fun = sfun) |> + summarize_row_groups() |> analyze("AGE") expect_error(result <- build_table(lyt, df = ANL), "ABC") }) test_that("add_overall_col with no col splits works", { - lyt <- basic_table() %>% - add_overall_col("whaaat") %>% + lyt <- basic_table() |> + add_overall_col("whaaat") |> analyze("AGE", mean) tab <- build_table(lyt, DM) ## previously error expect_identical(names(tab), "whaaat") @@ -285,9 +285,9 @@ test_that("add_overall_col with no col splits works", { test_that("cell_values works when you path all the way to the row", { - tbl <- basic_table() %>% - split_cols_by("ARM") %>% - analyze(c("SEX", "AGE")) %>% + tbl <- basic_table() |> + split_cols_by("ARM") |> + analyze(c("SEX", "AGE")) |> build_table(ex_adsl) res <- cell_values(tbl, c("AGE", "Mean"), c("ARM", "B: Placebo")) expect_identical(res[[1]], mean(subset(ex_adsl, ARM == "B: Placebo")$AGE)) @@ -306,14 +306,14 @@ test_that("inclNAs with empty factor levels behaves", { ## NO TIBBLES!!!!!!!!!!!!!!!!!!! dfdm <- as.data.frame(DM) - tbl <- basic_table() %>% - split_rows_by("RACE") %>% - analyze("COUNTRY", function(x) in_rows(nobs = length(x)), inclNAs = TRUE) %>% + tbl <- basic_table() |> + split_rows_by("RACE") |> + analyze("COUNTRY", function(x) in_rows(nobs = length(x)), inclNAs = TRUE) |> build_table(dfdm) - tbl2 <- basic_table() %>% - split_rows_by("RACE") %>% - analyze("COUNTRY", function(x) in_rows(nobs = length(x)), inclNAs = FALSE) %>% + tbl2 <- basic_table() |> + split_rows_by("RACE") |> + analyze("COUNTRY", function(x) in_rows(nobs = length(x)), inclNAs = FALSE) |> build_table(dfdm) expect_identical(tbl, tbl2) }) @@ -324,13 +324,13 @@ test_that("column labeling works correctly when value label var is a factor", { ex_adsl$ARMLAB <- factor(ex_adsl$ARM, labels = c("Drug X", "Placebo", "Combination") ) - lyt_orig <- basic_table() %>% - split_cols_by("ARM") %>% + lyt_orig <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "BMRKR2")) tbl_orig <- build_table(lyt_orig, ex_adsl) - lyt_lab <- basic_table() %>% - split_cols_by("ARM", labels_var = "ARMLAB") %>% + lyt_lab <- basic_table() |> + split_cols_by("ARM", labels_var = "ARMLAB") |> analyze(c("AGE", "BMRKR2")) tbl_lab <- build_table(lyt_lab, ex_adsl) @@ -351,22 +351,22 @@ test_that("column labeling works correctly when value label var is a factor", { ## pathing regression tests test_that("pathing works", { ## issue https://github.com/insightsengineering/rtables/issues/172 - result_overall <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - add_overall_col("overall") %>% - analyze(c("AGE", "SEX")) %>% + result_overall <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + add_overall_col("overall") |> + analyze(c("AGE", "SEX")) |> build_table(ex_adsl) va <- value_at(result_overall, c("AGE", "Mean"), c("ARM", "C: Combination")) expect_identical(va, result_overall[2, 3, drop = TRUE]) ## issue https://github.com/insightsengineering/rtables/issues/178 - t2 <- basic_table() %>% - split_cols_by("ARMCD") %>% - split_rows_by("COUNTRY", split_fun = keep_split_levels("CHN")) %>% - analyze("SEX") %>% - analyze("AGE", nested = FALSE) %>% - analyze("BMRKR1") %>% + t2 <- basic_table() |> + split_cols_by("ARMCD") |> + split_rows_by("COUNTRY", split_fun = keep_split_levels("CHN")) |> + analyze("SEX") |> + analyze("AGE", nested = FALSE) |> + analyze("BMRKR1") |> build_table(ex_adsl) ## this may get changed, but for now enforce it @@ -392,7 +392,7 @@ test_that("in_rows doesn't clobber cell format when only 1 row", { afun <- function(x) { in_rows("name" = rcell(123.31241231, format = "xx.xx")) } - lyt <- basic_table() %>% + lyt <- basic_table() |> analyze("AGE", afun = afun) tbl <- build_table(lyt, DM) mf <- matrix_form(tbl) @@ -430,12 +430,12 @@ test_that("no max is -Inf warnings from make_row_df when content rows exist in p stringsAsFactors = FALSE ) - lyt <- basic_table() %>% - split_rows_by("l1") %>% - summarize_row_groups() %>% - split_rows_by("l2") %>% - summarize_row_groups() %>% - split_rows_by("l3") %>% + lyt <- basic_table() |> + split_rows_by("l1") |> + summarize_row_groups() |> + split_rows_by("l2") |> + summarize_row_groups() |> + split_rows_by("l3") |> summarize_row_groups() tbl <- build_table(lyt, dat2) ## again, regexp of NA tests for ***no warnings*** @@ -447,14 +447,14 @@ test_that("no max is -Inf warnings from make_row_df when content rows exist in p test_that("specifying function format with no cfun in summarize_row_groups works", { formfun <- function(x, output) if (x[1] == 0) "0" else format_value(x, "xx (xx.x%)", output = output) - lyt <- basic_table() %>% - split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) %>% + lyt <- basic_table() |> + split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) |> split_rows_by("RACE", split_label = "Ethnicity", # 5 label_pos = "topleft", split_fun = keep_split_levels(c("ASIAN", "WHITE")) - ) %>% - summarize_row_groups(format = formfun) %>% # 4 + ) |> + summarize_row_groups(format = formfun) |> # 4 analyze("AGE", afun = mean, format = "xx.x") tbl <- build_table(lyt, DM[1:15, ]) # WHITE-F is 0 in the first 15 rows... @@ -474,16 +474,16 @@ test_that("child_label = hidden does not affect tree structure/pathing", { s_test <- function(df, ...) in_rows(mn = 1, sd = 2) - lyt <- basic_table() %>% - split_cols_by("ARM", ref_group = "ARM A") %>% - split_rows_by("FCT", child_labels = "hidden") %>% + lyt <- basic_table() |> + split_cols_by("ARM", ref_group = "ARM A") |> + split_rows_by("FCT", child_labels = "hidden") |> analyze("val", afun = s_test) tbl <- build_table(lyt, df) - lyt2 <- basic_table() %>% - split_cols_by("ARM", ref_group = "ARM A") %>% - split_rows_by("FCT") %>% + lyt2 <- basic_table() |> + split_cols_by("ARM", ref_group = "ARM A") |> + split_rows_by("FCT") |> analyze("val", afun = s_test) tbl2 <- build_table(lyt2, df) @@ -514,14 +514,14 @@ test_that("child_label = hidden does not affect tree structure/pathing", { ## ensure nested = FALSE not needed after analyze test_that("nested = FALSE not needed after analyze", { - lyt1 <- basic_table() %>% - analyze("AGE") %>% - split_rows_by("STRATA1") %>% + lyt1 <- basic_table() |> + analyze("AGE") |> + split_rows_by("STRATA1") |> analyze("AGE") - lyt2 <- basic_table() %>% - analyze("AGE") %>% - split_rows_by("STRATA1", nested = FALSE) %>% + lyt2 <- basic_table() |> + analyze("AGE") |> + split_rows_by("STRATA1", nested = FALSE) |> analyze("AGE") expect_identical(lyt1, lyt2) @@ -556,11 +556,11 @@ test_that("indent mod preserved when paginating between multi-analyses", { lapply(tab, count_pct, .N_col = .N_col) } - lyt3 <- basic_table() %>% - split_cols_by("ARM") %>% - summarize_row_groups("USUBJID", label_fstr = "Number of Patients", format = "xx") %>% - analyze("SEX", tab_w_pct, var_labels = "Gender", indent_mod = -1) %>% - analyze("smoker", tab_w_pct, indent_mod = -1) %>% + lyt3 <- basic_table() |> + split_cols_by("ARM") |> + summarize_row_groups("USUBJID", label_fstr = "Number of Patients", format = "xx") |> + analyze("SEX", tab_w_pct, var_labels = "Gender", indent_mod = -1) |> + analyze("smoker", tab_w_pct, indent_mod = -1) |> analyze("age_grp", tab_w_pct, indent_mod = -1) tab <- build_table(lyt3, adsl2) @@ -578,23 +578,23 @@ test_that("indent mod preserved when paginating between multi-analyses", { ## https://github.com/insightsengineering/rtables/issues/634 ## problem was actually in formatters fixed there in PR #152 test_that("export_as_txt works when there are newlines in column labels (naturally or after wrapping", { - tbl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% + tbl <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ACTARM") |> split_rows_by( "PARAMCD", labels_var = "PARAM", split_fun = drop_split_levels - ) %>% + ) |> split_rows_by( "AVISIT", split_fun = drop_split_levels, label_pos = "hidden" - ) %>% + ) |> split_cols_by_multivar( vars = c("AVAL", "CHG"), varlabels = c("Analysis Value", "Change from\nBaseline") - ) %>% - analyze_colvars(afun = mean) %>% + ) |> + analyze_colvars(afun = mean) |> build_table(formatters::ex_adlb) expect_silent(tmp <- export_as_txt(tbl, lpp = 20)) @@ -608,9 +608,9 @@ test_that("overridden colcounts via build_table are used during tabulation corre .N_col } - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA1") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("STRATA1") |> analyze("AGE", afun = afun) tbl <- build_table(lyt, ex_adsl, col_counts = 1:9) diff --git a/tests/testthat/test-result_data_frame.R b/tests/testthat/test-result_data_frame.R index ef225a1eed..d5fb2d7ec6 100644 --- a/tests/testthat/test-result_data_frame.R +++ b/tests/testthat/test-result_data_frame.R @@ -22,9 +22,9 @@ test_that("Result Data Frame generation works v0", { ) ## handle multiple analyses - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("STRATA1") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("STRATA1") |> analyze(c("AGE", "BMRKR2")) tbl2 <- build_table(lyt, ex_adsl) @@ -39,8 +39,8 @@ test_that("Result Data Frame generation works v0", { b = c(1, NA) ) - lyt3 <- basic_table() %>% - split_cols_by_multivar(c("a", "b")) %>% + lyt3 <- basic_table() |> + split_cols_by_multivar(c("a", "b")) |> analyze_colvars(afun = length, inclNAs = TRUE) tbl3 <- build_table(lyt3, test) @@ -49,8 +49,8 @@ test_that("Result Data Frame generation works v0", { expect_identical(nrow(result_df3), 1L) ## test labels when no row splits - lyt4 <- basic_table() %>% - split_cols_by("ARM") %>% + lyt4 <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "SEX")) tbl4 <- build_table(lyt4, DM) @@ -91,10 +91,10 @@ test_that("as_result_df works with visual output (data_format as numeric)", { rownames(string_tbl) <- NULL expect_equal(res, string_tbl) - expect_silent(basic_table() %>% build_table(DM) %>% as_result_df()) + expect_silent(basic_table() |> build_table(DM) |> as_result_df()) - tbl <- basic_table(show_colcounts = TRUE) %>% - analyze("BMRKR1") %>% + tbl <- basic_table(show_colcounts = TRUE) |> + analyze("BMRKR1") |> build_table(DM) expect_equal(as_result_df(tbl)$`all obs`, 5.851948, tolerance = 1e-6) expect_equal( @@ -106,9 +106,9 @@ test_that("as_result_df works with visual output (data_format as numeric)", { # Test for integer extraction and ranges - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("STRATA1") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("STRATA1") |> analyze("AGE", afun = function(x) list(a = mean(x), b = range(x))) tbl <- build_table(lyt, ex_adsl) @@ -134,9 +134,9 @@ test_that("as_result_df works with visual output (data_format as numeric)", { test_that("as_result_df works fine also with multiple rbind_root", { # regression test for rtables#815 - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("STRATA1") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("STRATA1") |> analyze(c("AGE", "BMRKR2")) tbl <- build_table(lyt, ex_adsl) @@ -150,10 +150,10 @@ test_that("as_result_df works fine also with multiple rbind_root", { test_that("as_result_df keeps label rows", { # regression test for rtables#815 - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA2") %>% - split_rows_by("STRATA1") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("STRATA2") |> + split_rows_by("STRATA1") |> analyze(c("AGE", "BMRKR2")) tbl <- build_table(lyt, ex_adsl) @@ -171,7 +171,7 @@ test_that("as_result_df keeps label rows", { expect_identical(ncol(rd1), ncol(rd4)) expect_identical(as.character(rd1[3, ]), as.character(rd2[5, ])) - expect_identical(rd3[["A: Drug X.S1"]], rd4[["A: Drug X.S1"]] %>% unlist()) + expect_identical(rd3[["A: Drug X.S1"]], rd4[["A: Drug X.S1"]] |> unlist()) # More challenging labels lyt <- make_big_lyt() @@ -210,12 +210,12 @@ test_that("as_result_df simplify is producing a data.frame that is compatible wi expect_identical( ard_out$label_name, - df_to_tt(ard_out) %>% row.names() + df_to_tt(ard_out) |> row.names() ) init_tbl <- df_to_tt(mtcars) - end_tbl <- init_tbl %>% - as_result_df(simplify = TRUE) %>% + end_tbl <- init_tbl |> + as_result_df(simplify = TRUE) |> df_to_tt() expect_equal( @@ -225,7 +225,7 @@ test_that("as_result_df simplify is producing a data.frame that is compatible wi }) test_that("as_result_df works fine with empty tables and no character(0) is allowed", { - tbl <- basic_table() %>% + tbl <- basic_table() |> build_table(mtcars) expect_silent(as_result_df(tbl)) @@ -241,9 +241,9 @@ test_that("as_result_df works fine with empty tables and no character(0) is allo }) test_that("as_result_df works with analyze-only tables (odd num of path elements)", { - tbl <- basic_table() %>% - analyze("cyl", table_names = "a") %>% - analyze("mpg") %>% + tbl <- basic_table() |> + analyze("cyl", table_names = "a") |> + analyze("mpg") |> build_table(mtcars) expect_equal(as_result_df(tbl, add_tbl_name_split = TRUE)$group1[[1]], "") @@ -289,9 +289,9 @@ test_that("make_ard produces realistic ARD output with as_result_df", { ) } - lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>% - split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "B: Placebo"))) %>% - analyze(vars = "AGE", afun = mean_sd_custom) %>% + lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") |> + split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "B: Placebo"))) |> + analyze(vars = "AGE", afun = mean_sd_custom) |> analyze(vars = "SEX", afun = counts_percentage_custom) tbl <- build_table(lyt, ex_adsl) @@ -334,8 +334,8 @@ test_that("make_ard produces realistic ARD output with as_result_df", { ) # Default values - lyt <- basic_table() %>% - split_cols_by("ARM") %>% + lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ex_adsl) @@ -345,10 +345,10 @@ test_that("make_ard produces realistic ARD output with as_result_df", { }) test_that("make_ard works with multiple row levels", { - lyt <- basic_table() %>% - split_rows_by("STRATA1") %>% - split_rows_by("STRATA2") %>% - split_cols_by("ARM") %>% + lyt <- basic_table() |> + split_rows_by("STRATA1") |> + split_rows_by("STRATA2") |> + split_cols_by("ARM") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ex_adsl) @@ -379,10 +379,10 @@ test_that("make_ard works with multiple row levels", { }) test_that("make_ard works with multiple column levels", { - lyt <- basic_table() %>% - split_rows_by("STRATA1") %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA2") %>% + lyt <- basic_table() |> + split_rows_by("STRATA1") |> + split_cols_by("ARM") |> + split_cols_by("STRATA2") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ex_adsl) @@ -414,12 +414,12 @@ test_that("make_ard works with multiple column levels", { }) test_that("make_ard works with summarize_row_groups", { - lyt <- basic_table() %>% - split_rows_by("STRATA2") %>% - summarize_row_groups() %>% - split_rows_by("ARM") %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA1") %>% + lyt <- basic_table() |> + split_rows_by("STRATA2") |> + summarize_row_groups() |> + split_rows_by("ARM") |> + split_cols_by("ARM") |> + split_cols_by("STRATA1") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ex_adsl) @@ -452,12 +452,12 @@ test_that("make_ard works with summarize_row_groups", { ) # Testing different placements of summarize_row_groups - lyt <- basic_table() %>% - split_rows_by("STRATA2") %>% - split_rows_by("ARM") %>% - summarize_row_groups() %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA1") %>% + lyt <- basic_table() |> + split_rows_by("STRATA2") |> + split_rows_by("ARM") |> + summarize_row_groups() |> + split_cols_by("ARM") |> + split_cols_by("STRATA1") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ex_adsl) @@ -496,8 +496,8 @@ test_that("make_ard works if there are no stat_names", { ) } - lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>% - split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "B: Placebo"))) %>% + lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") |> + split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "B: Placebo"))) |> analyze(vars = "AGE", afun = mean_sd_custom) tbl <- build_table(lyt, ex_adsl) @@ -506,22 +506,22 @@ test_that("make_ard works if there are no stat_names", { }) test_that("make_ard works if string precision is needed", { - lyt <- basic_table() %>% - split_rows_by("ARM") %>% - summarize_row_groups() %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA1") %>% + lyt <- basic_table() |> + split_rows_by("ARM") |> + summarize_row_groups() |> + split_cols_by("ARM") |> + split_cols_by("STRATA1") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ex_adsl) # Some edge cases expect_equal( - as_result_df(tbl[, 1], make_ard = TRUE) %>% dim(), + as_result_df(tbl[, 1], make_ard = TRUE) |> dim(), c(21, 12) ) expect_equal( - as_result_df(tbl[1, ], make_ard = TRUE) %>% dim(), + as_result_df(tbl[1, ], make_ard = TRUE) |> dim(), c(18, 12) ) @@ -545,7 +545,7 @@ test_that("make_ard works with split_cols_by_multivar", { gender = factor(sample(c("Female", "Male"), n, replace = TRUE), levels = c("Female", "Male")), handed = factor(sample(c("Left", "Right"), n, prob = c(.6, .4), replace = TRUE), levels = c("Left", "Right")), age = rchisq(n, 30) + 10 - ) %>% mutate( + ) |> mutate( weight = 35 * rnorm(n, sd = .5) + ifelse(gender == "Female", 140, 180) ) @@ -554,11 +554,11 @@ test_that("make_ard works with split_cols_by_multivar", { function(x) in_rows("# x > 5" = sum(x > .5), .formats = "xx") ) - lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by_multivar(c("age", "weight")) %>% - split_rows_by("country") %>% - summarize_row_groups() %>% + lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by_multivar(c("age", "weight")) |> + split_rows_by("country") |> + summarize_row_groups() |> analyze_colvars(afun = colfuns) tbl <- build_table(lyt, df) @@ -577,10 +577,10 @@ test_that("make_ard works when printed format differs from cell values", { } } - test_out <- basic_table() %>% - split_rows_by("ARM") %>% - split_cols_by("ARM") %>% - analyze(vars = "AGE", afun = mean_sd_custom) %>% + test_out <- basic_table() |> + split_rows_by("ARM") |> + split_cols_by("ARM") |> + analyze(vars = "AGE", afun = mean_sd_custom) |> build_table(DM) expect_warning( diff --git a/tests/testthat/test-sanitize-struct.R b/tests/testthat/test-sanitize-struct.R index 6e080f81c6..ac821c486a 100644 --- a/tests/testthat/test-sanitize-struct.R +++ b/tests/testthat/test-sanitize-struct.R @@ -3,9 +3,9 @@ context("table structure validation") test_that("table structure validation and sanitization work", { bad_dat <- DM bad_dat$RACE <- NA - bad_lyt1 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE") %>% + bad_lyt1 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE") |> analyze("AGE") bad_tab1 <- build_table(bad_lyt1, bad_dat) @@ -29,10 +29,10 @@ test_that("table structure validation and sanitization work", { col_info(bad_tab1) ) - bad_lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE") %>% - split_rows_by("SEX") %>% + bad_lyt2 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE") |> + split_rows_by("SEX") |> summarize_row_groups() bad_tab2 <- build_table(bad_lyt2, DM) diff --git a/tests/testthat/test-sort-prune.R b/tests/testthat/test-sort-prune.R index a697fa4720..f86d8b9361 100644 --- a/tests/testthat/test-sort-prune.R +++ b/tests/testthat/test-sort-prune.R @@ -1,13 +1,13 @@ context("sorting and pruning") -rawtable <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("SEX") %>% - split_rows_by("RACE") %>% - summarize_row_groups() %>% - split_rows_by("STRATA1") %>% - summarize_row_groups() %>% - analyze("AGE") %>% +rawtable <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> + split_rows_by("RACE") |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> + summarize_row_groups() |> + analyze("AGE") |> build_table(DM) @@ -30,10 +30,10 @@ test_that("pruning and trimming work", { all_zero_or_na(tt) } - smallertab <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% - analyze("AGE") %>% + smallertab <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + analyze("AGE") |> build_table(DM) ptab <- prune_table(smallertab, silly_prune) @@ -45,11 +45,11 @@ test_that("pruning and trimming work", { ) - biggertab <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% - split_rows_by("STRATA1") %>% - analyze("AGE") %>% + biggertab <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + split_rows_by("STRATA1") |> + analyze("AGE") |> build_table(subset(DM, STRATA1 != "C")) ## something trimmed from every outer facet @@ -67,11 +67,11 @@ test_that("pruning and trimming work", { ## ensure/retain structure unawareness of trim_rows expect_identical(dim(trm1), c(6L, 3L)) - smallertab2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% - summarize_row_groups() %>% - analyze("AGE") %>% + smallertab2 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + summarize_row_groups() |> + analyze("AGE") |> build_table(DM) expect_identical( @@ -96,11 +96,11 @@ test_that("pruning and trimming work", { }) test_that("provided score functions work", { - smallertab2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% - summarize_row_groups() %>% - analyze("AGE") %>% + smallertab2 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + summarize_row_groups() |> + analyze("AGE") |> build_table(DM) kids <- tree_children(smallertab2) scores <- sapply(kids, cont_n_allcols) @@ -134,10 +134,10 @@ test_that("sort_at_path just returns an empty input table", { }) test_that("trim_rows and prune_table do the same thing in normal cases", { - bigtbl <- basic_table() %>% - split_rows_by("RACE") %>% - split_rows_by("COUNTRY") %>% - analyze("AGE") %>% + bigtbl <- basic_table() |> + split_rows_by("RACE") |> + split_rows_by("COUNTRY") |> + analyze("AGE") |> build_table(ex_adsl) ptbl <- prune_table(bigtbl) @@ -192,23 +192,23 @@ test_that("provided score functions throw informative errors when invalid and * } - lyt_raw <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM", split_fun = add_overall_level("total", first = FALSE)) %>% - summarize_row_groups("AETOXGR", cfun = basic_grade_count, extra_args = list(grade_groups = grade_groups_dict)) %>% + lyt_raw <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ACTARM", split_fun = add_overall_level("total", first = FALSE)) |> + summarize_row_groups("AETOXGR", cfun = basic_grade_count, extra_args = list(grade_groups = grade_groups_dict)) |> split_rows_by("AEBODSYS", indent_mod = -1, split_fun = drop_split_levels, label_pos = "topleft", split_label = "aebod sys label", child_labels = "visible" - ) %>% - summarize_row_groups("AETOXGR", cfun = basic_grade_count, extra_args = list(grade_groups = grade_groups_dict)) %>% + ) |> + summarize_row_groups("AETOXGR", cfun = basic_grade_count, extra_args = list(grade_groups = grade_groups_dict)) |> split_rows_by("AEDECOD", indent_mod = -1, split_fun = drop_split_levels, label_pos = "topleft", split_label = "aedecod label" - ) %>% + ) |> analyze("AETOXGR", basic_grade_count, extra_args = list(grade_groups = grade_groups_dict), @@ -276,11 +276,11 @@ test_that("provided score functions throw informative errors when invalid and * }) test_that("paths come out correct when sorting with '*'", { - tbl <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE") %>% - summarize_row_groups() %>% - analyze("STRATA1") %>% + tbl <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE") |> + summarize_row_groups() |> + analyze("STRATA1") |> build_table(DM) scorefun <- function(tt) sum(unlist(row_values(tt))) @@ -306,12 +306,12 @@ test_that("sort_at_path works with uniqified names", { adsl <- ex_adsl adsl$flag <- sample(c("Y", "N"), nrow(adsl), replace = TRUE) - lyt <- basic_table() %>% - split_rows_by("flag", split_fun = keep_split_levels("Y")) %>% - split_rows_by("SEX") %>% - analyze("BMRKR1") %>% - split_rows_by("flag", split_fun = keep_split_levels("Y")) %>% - split_rows_by("SEX") %>% + lyt <- basic_table() |> + split_rows_by("flag", split_fun = keep_split_levels("Y")) |> + split_rows_by("SEX") |> + analyze("BMRKR1") |> + split_rows_by("flag", split_fun = keep_split_levels("Y")) |> + split_rows_by("SEX") |> analyze("AGE") tbl <- build_table(lyt, adsl) @@ -328,8 +328,8 @@ test_that("passing extra stuff to sorting and pruning works", { force(myarg) ## cause error if it isn't passed TRUE } - lyt <- basic_table() %>% - split_rows_by("STRATA1") %>% + lyt <- basic_table() |> + split_rows_by("STRATA1") |> analyze("SEX") tbl <- build_table(lyt, ex_adsl) diff --git a/tests/testthat/test-tab_afun_cfun.R b/tests/testthat/test-tab_afun_cfun.R index 54470d987e..747a17b03a 100644 --- a/tests/testthat/test-tab_afun_cfun.R +++ b/tests/testthat/test-tab_afun_cfun.R @@ -6,12 +6,12 @@ test_that(".spl_context contains information about the column split", { ## Duplication hack -> This would need to use split_cols_by_multivar(...) # Workaround for #690 - DM_tmp <- DM %>% + DM_tmp <- DM |> mutate(method = factor("Mean")) DM_tmp <- rbind( DM_tmp, - DM_tmp %>% mutate(method = factor("SD")) + DM_tmp |> mutate(method = factor("SD")) ) analysis_fun_fin <- function(x, .spl_context, labelstr = "", ...) { @@ -28,15 +28,15 @@ test_that(".spl_context contains information about the column split", { in_rows(.list = res) } - lyt <- basic_table() %>% - split_rows_by("STRATA1") %>% - split_cols_by(var = "method") %>% - split_cols_by("SEX", split_fun = drop_split_levels) %>% + lyt <- basic_table() |> + split_rows_by("STRATA1") |> + split_cols_by(var = "method") |> + split_cols_by("SEX", split_fun = drop_split_levels) |> analyze(vars = "BMRKR1", afun = analysis_fun_fin, format = "xx.xxx") - expect_silent(tbl <- lyt %>% build_table(DM_tmp)) + expect_silent(tbl <- lyt |> build_table(DM_tmp)) - DM_B_F <- DM %>% filter(SEX == "F", STRATA1 == "B") + DM_B_F <- DM |> filter(SEX == "F", STRATA1 == "B") expect_equal(tbl[4, 1, drop = TRUE], mean(DM_B_F$BMRKR1)) expect_equal(tbl[4, 3, drop = TRUE], sd(DM_B_F$BMRKR1)) }) @@ -90,31 +90,31 @@ test_that(".spl_context and afun extra parameters contain information about comb FUN.VALUE = character(1) ) # Use of cexpr - alt_df1c <- .alt_df_row %>% + alt_df1c <- .alt_df_row |> filter(eval(.all_col_exprs[[AC_colname[1]]])) - alt_df2c <- .alt_df_row %>% + alt_df2c <- .alt_df_row |> filter(eval(.all_col_exprs[[AC_colname[2]]])) # Normal execution - no use of cexpr - alt_df1 <- .alt_df_row %>% + alt_df1 <- .alt_df_row |> filter( ARM == "A: Drug X", COUNTRY == .spl_context$cur_col_split_val[[1]][2] ) - alt_df2 <- .alt_df_row %>% + alt_df2 <- .alt_df_row |> filter( ARM == "C: Combination", COUNTRY == .spl_context$cur_col_split_val[[1]][2] ) # Super manual extraction - alt_df1b <- alt_counts_df %>% + alt_df1b <- alt_counts_df |> filter( ARM == "A: Drug X", COUNTRY == .spl_context$cur_col_split_val[[1]][2], SEX == .spl_context$value[3] ) - alt_df2b <- alt_counts_df %>% + alt_df2b <- alt_counts_df |> filter( ARM == "C: Combination", COUNTRY == .spl_context$cur_col_split_val[[1]][2], @@ -123,9 +123,9 @@ test_that(".spl_context and afun extra parameters contain information about comb # All strata is add_overall_level -> filter not needed if (.spl_context$value[[2]] != "All Strata") { - alt_df1b <- alt_df1b %>% + alt_df1b <- alt_df1b |> filter(STRATA1 == .spl_context$value[[2]]) - alt_df2b <- alt_df2b %>% + alt_df2b <- alt_df2b |> filter(STRATA1 == .spl_context$value[[2]]) } @@ -156,21 +156,21 @@ test_that(".spl_context and afun extra parameters contain information about comb } } - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM", split_fun = add_combo_levels(combodf, first = TRUE)) %>% - split_cols_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) %>% - split_rows_by("STRATA1", split_fun = add_overall_level("All Strata")) %>% - split_rows_by("SEX", split_fun = keep_split_levels(c("F", "M"))) %>% - add_overall_col("All Patients 2") %>% + lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", split_fun = add_combo_levels(combodf, first = TRUE)) |> + split_cols_by("COUNTRY", split_fun = keep_split_levels(c("CHN", "USA"))) |> + split_rows_by("STRATA1", split_fun = add_overall_level("All Strata")) |> + split_rows_by("SEX", split_fun = keep_split_levels(c("F", "M"))) |> + add_overall_col("All Patients 2") |> analyze(vars = "BMRKR1", afun = n_wrapper_alt_df(ex_adsl)) # NB: If you add keep_levels = c("all_X") to add_combo_levels the other # column expressions are missing -> Expected! - expect_error(lyt %>% build_table(DM), + expect_error(lyt |> build_table(DM), regexp = "Layout contains afun\\/cfun functions that have optional*" ) - tbl <- lyt %>% build_table(DM, alt_counts_df = ex_adsl) + tbl <- lyt |> build_table(DM, alt_counts_df = ex_adsl) expect_silent(cbind_rtables(tbl, tbl)) expect_message(rbind(tbl, tbl)) # uniqify message @@ -178,10 +178,10 @@ test_that(".spl_context and afun extra parameters contain information about comb spl_ctx_cnt <- lapply(seq(8, nrow(tbl), 5), function(x) tbl[x, 2, drop = TRUE]) nrow_manual <- lapply(sort(unique(ex_adsl$STRATA1)), function(x) { - tmp_strata <- ex_adsl %>% filter(STRATA1 == x, SEX == "F", COUNTRY == "USA") + tmp_strata <- ex_adsl |> filter(STRATA1 == x, SEX == "F", COUNTRY == "USA") sapply(list( - tmp_strata %>% filter(ARM == "A: Drug X"), - tmp_strata %>% filter(ARM == "C: Combination") + tmp_strata |> filter(ARM == "A: Drug X"), + tmp_strata |> filter(ARM == "C: Combination") ), nrow) }) @@ -191,14 +191,14 @@ test_that(".spl_context and afun extra parameters contain information about comb test_that("Error localization for missing split variable when done in alt_count_df", { # Error we want to happen afun_tmp <- function(x, .alt_df_row, ...) mean(x) - lyt_col <- basic_table() %>% - split_cols_by("ARMCD") %>% + lyt_col <- basic_table() |> + split_cols_by("ARMCD") |> analyze("BMRKR1", afun = afun_tmp) - lyt_row <- basic_table() %>% - split_rows_by("ARMCD") %>% + lyt_row <- basic_table() |> + split_rows_by("ARMCD") |> analyze("BMRKR1", afun = afun_tmp) - expect_error(lyt_col %>% build_table(ex_adsl, alt_counts_df = DM)) - expect_error(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM), + expect_error(lyt_col |> build_table(ex_adsl, alt_counts_df = DM)) + expect_error(lyt_row |> build_table(ex_adsl, alt_counts_df = DM), regexp = paste0( "Following error encountered in splitting ", "alt_counts_df: variable\\(s\\) \\[ARMCD\\] ", @@ -208,21 +208,21 @@ test_that("Error localization for missing split variable when done in alt_count_ # What if it is not asked by the function? afun_tmp <- function(x, ...) mean(x) - lyt_col <- basic_table() %>% - split_cols_by("ARMCD") %>% + lyt_col <- basic_table() |> + split_cols_by("ARMCD") |> analyze("BMRKR1", afun = afun_tmp) - lyt_row <- basic_table() %>% - split_rows_by("STRATA1", split_fun = keep_split_levels("A")) %>% - split_rows_by("ARMCD") %>% + lyt_row <- basic_table() |> + split_rows_by("STRATA1", split_fun = keep_split_levels("A")) |> + split_rows_by("ARMCD") |> analyze("BMRKR1", afun = afun_tmp) # Error on the columns should happen because it is used for counts on column space expect_error( - lyt_col %>% build_table(ex_adsl, alt_counts_df = DM), + lyt_col |> build_table(ex_adsl, alt_counts_df = DM), "alt_counts_df appears incompatible with column-split structure*" ) - expect_silent(lyt_col %>% build_table(ex_adsl)) # it is specific of alt_counts_df - expect_silent(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM)) + expect_silent(lyt_col |> build_table(ex_adsl)) # it is specific of alt_counts_df + expect_silent(lyt_row |> build_table(ex_adsl, alt_counts_df = DM)) }) test_that("Error localization for missmatch split variable when done in alt_count_df", { @@ -238,56 +238,56 @@ test_that("Error localization for missmatch split variable when done in alt_coun stopifnot(as.character(check_val) == .spl_context$value[2]) mean(x) } - lyt_row <- basic_table() %>% - split_rows_by("ARMCD") %>% + lyt_row <- basic_table() |> + split_rows_by("ARMCD") |> analyze("BMRKR1", afun = afun_tmp) # Mismatch in the number of splits (NA is 0) - DM_tmp <- DM %>% mutate("ARMCD" = NA_character_) - expect_error(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp), + DM_tmp <- DM |> mutate("ARMCD" = NA_character_) + expect_error(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp), regexp = paste0("alt_counts_df split variable\\(s\\) \\[ARMCD\\] *") ) # Mismatch of levels armcd_col <- factor(sample(c("arm A", "arm B", "arm C"), nrow(DM), replace = TRUE)) - DM_tmp <- DM %>% mutate("ARMCD" = armcd_col) - expect_error(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp), + DM_tmp <- DM |> mutate("ARMCD" = armcd_col) + expect_error(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp), regexp = paste0("alt_counts_df split variable\\(s\\) \\[ARMCD\\] *") ) # Mix mismatch of levels armcd_col <- factor(sample(c("arm A", "ARM B", "ARM C"), nrow(DM), replace = TRUE)) - DM_tmp <- DM %>% mutate("ARMCD" = armcd_col) - expect_error(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp), + DM_tmp <- DM |> mutate("ARMCD" = armcd_col) + expect_error(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp), regexp = paste0("alt_counts_df split variable\\(s\\) \\[ARMCD\\] *") ) # Mismatch in the number of levels armcd_col2 <- factor(sample(levels(ex_adsl$ARMCD)[c(1, 2)], nrow(DM), replace = TRUE)) - DM_tmp <- DM %>% mutate("ARMCD" = armcd_col2) - expect_error(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp), + DM_tmp <- DM |> mutate("ARMCD" = armcd_col2) + expect_error(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp), regexp = paste0("alt_counts_df split variable\\(s\\) \\[ARMCD\\] *") ) # Another order -> should work? yes, split is valid levels(armcd_col) <- levels(ex_adsl$ARMCD)[c(1, 3, 2)] - DM_tmp <- DM %>% mutate("ARMCD" = armcd_col) - expect_silent(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp)) + DM_tmp <- DM |> mutate("ARMCD" = armcd_col) + expect_silent(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp)) # Mix mismatch of levels but covering them all -> valid split armcd_col <- factor(sample(c("arm A", levels(ex_adsl$ARMCD)), nrow(DM), replace = TRUE)) - DM_tmp <- DM %>% mutate("ARMCD" = armcd_col) - expect_silent(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp)) + DM_tmp <- DM |> mutate("ARMCD" = armcd_col) + expect_silent(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp)) # Values are all NA, but the levels are correct DM_tmp$ARMCD <- factor(NA, levels = levels(ex_adsl$ARMCD)) - expect_error(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp), + expect_error(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp), regexp = paste0("alt_counts_df split variable\\(s\\) \\[ARMCD\\] *") ) DM_tmp$ARMCD <- factor(NA, levels = levels(ex_adsl$ARMCD)) DM_tmp$ARMCD[seq_along(levels(ex_adsl$ARMCD))] <- levels(ex_adsl$ARMCD) - expect_silent(lyt_row %>% build_table(ex_adsl, alt_counts_df = DM_tmp)) + expect_silent(lyt_row |> build_table(ex_adsl, alt_counts_df = DM_tmp)) }) context("Content functions (cfun)") @@ -297,9 +297,9 @@ test_that(".alt_df_row appears in cfun but not in afun.", { require(dplyr, quietly = TRUE) # Adding STRATA2 col to DM for alt_counts_df col split - alt_tmp <- DM %>% left_join( - ex_adsl %>% - mutate(ID = paste0("S", seq_len(nrow(ex_adsl)))) %>% + alt_tmp <- DM |> left_join( + ex_adsl |> + mutate(ID = paste0("S", seq_len(nrow(ex_adsl)))) |> select(ID, STRATA2) ) @@ -314,11 +314,11 @@ test_that(".alt_df_row appears in cfun but not in afun.", { ...) { if (!missing(.alt_df_row)) { # .alt_df_row is only row-splitted matter - stopifnot(nrow(alt_tmp %>% filter(STRATA1 == "A")) == nrow(.alt_df_row)) + stopifnot(nrow(alt_tmp |> filter(STRATA1 == "A")) == nrow(.alt_df_row)) # Filtered column number of elements correspond to .N_col stopifnot(nrow( - alt_tmp %>% + alt_tmp |> filter(eval(.spl_context$cur_col_expr[[1]])) ) == .N_col) } else { @@ -344,23 +344,23 @@ test_that(".alt_df_row appears in cfun but not in afun.", { ) } - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("SEX", split_fun = keep_split_levels(c("F", "U"))) %>% - split_cols_by("STRATA2", split_fun = keep_split_levels("S1")) %>% - split_rows_by("STRATA1", split_fun = keep_split_levels("A")) %>% - summarize_row_groups(var = "BMRKR1", cfun = cfun_tmp) %>% - split_rows_by("ARMCD") %>% + lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("SEX", split_fun = keep_split_levels(c("F", "U"))) |> + split_cols_by("STRATA2", split_fun = keep_split_levels("S1")) |> + split_rows_by("STRATA1", split_fun = keep_split_levels("A")) |> + summarize_row_groups(var = "BMRKR1", cfun = cfun_tmp) |> + split_rows_by("ARMCD") |> analyze("BMRKR1", afun = afun_tmp) expect_error( - lyt %>% build_table(ex_adsl), + lyt |> build_table(ex_adsl), "Layout contains afun/cfun functions that have optional*" ) expect_error( - lyt %>% build_table(ex_adsl, alt_counts_df = DM), + lyt |> build_table(ex_adsl, alt_counts_df = DM), "alt_counts_df appears incompatible with column-split*" ) - expect_silent(lyt %>% build_table(ex_adsl, alt_counts_df = alt_tmp)) + expect_silent(lyt |> build_table(ex_adsl, alt_counts_df = alt_tmp)) }) @@ -373,11 +373,11 @@ test_that("full alt_counts_df is accessible from afun/cfun via .alt_df_full", { } } ## row labels will be nonsense but we don't care about that for this check - lyt <- basic_table() %>% - split_cols_by("SEX") %>% - split_cols_by("STRATA1") %>% - split_rows_by("AEBODSYS", split_fun = trim_levels_in_group("AEDECOD")) %>% - summarize_row_groups("AEBODSYS", cfun = fun, format = "xx") %>% + lyt <- basic_table() |> + split_cols_by("SEX") |> + split_cols_by("STRATA1") |> + split_rows_by("AEBODSYS", split_fun = trim_levels_in_group("AEDECOD")) |> + summarize_row_groups("AEBODSYS", cfun = fun, format = "xx") |> analyze("AEDECOD", afun = fun) tbl <- build_table(lyt, ex_adae[1:3, ], alt_counts_df = ex_adsl) diff --git a/vignettes/advanced_usage.Rmd b/vignettes/advanced_usage.Rmd index f7f4344ac6..ad2076e9c1 100644 --- a/vignettes/advanced_usage.Rmd +++ b/vignettes/advanced_usage.Rmd @@ -30,8 +30,8 @@ rtables provides an array of functions to control the splitting logic without cr ```{r} d1 <- subset(ex_adsl, AGE < 25) d1$AGE <- as.factor(d1$AGE) -lyt1 <- basic_table() %>% - split_cols_by("AGE") %>% +lyt1 <- basic_table() |> + split_cols_by("AGE") |> analyze("SEX") build_table(lyt1, d1) @@ -52,8 +52,8 @@ sd_cutfun <- function(x) { cutpoints } -lyt1 <- basic_table() %>% - split_cols_by_cutfun("AGE", cutfun = sd_cutfun) %>% +lyt1 <- basic_table() |> + split_cols_by_cutfun("AGE", cutfun = sd_cutfun) |> analyze("SEX") build_table(lyt1, ex_adsl) @@ -62,12 +62,12 @@ build_table(lyt1, ex_adsl) Alternatively, `split_*_by_cuts` can be used when breakpoints are predefined and `split_*_by_quartiles` when the data should be faceted by quantile. ```{r} -lyt1 <- basic_table() %>% +lyt1 <- basic_table() |> split_cols_by_cuts( "AGE", cuts = c(0, 30, 60, 100), cutlabels = c("0-30 y.o.", "30-60 y.o.", "60-100 y.o.") - ) %>% + ) |> analyze("SEX") build_table(lyt1, ex_adsl) @@ -108,8 +108,8 @@ picky_splitter <- function(var) { d1 <- subset(ex_adsl, ARM == "A: Drug X") d1$ARM <- factor(d1$ARM) -lyt1 <- basic_table() %>% - split_cols_by("ARM", split_fun = picky_splitter("ARM")) %>% +lyt1 <- basic_table() |> + split_cols_by("ARM", split_fun = picky_splitter("ARM")) |> analyze("AGE") ``` @@ -176,10 +176,10 @@ my_afun <- function(x, .spl_context) { ) } -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("AVISIT") %>% - split_cols_by_multivar(vars = c("AVAL", "CHG")) %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("AVISIT") |> + split_cols_by_multivar(vars = c("AVAL", "CHG")) |> analyze_colvars(my_afun) build_table(lyt, dta_test) @@ -211,10 +211,10 @@ my_afun <- function(x, .var, .spl_context) { ) } -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("AVISIT") %>% - split_cols_by_multivar(vars = c("AVAL", "CHG")) %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("AVISIT") |> + split_cols_by_multivar(vars = c("AVAL", "CHG")) |> analyze_colvars(my_afun) build_table(lyt, dta_test) @@ -244,10 +244,10 @@ my_afun <- function(x, .var, ref_rowgroup, .spl_context) { ) } -lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("AVISIT") %>% - split_cols_by_multivar(vars = c("AVAL", "CHG")) %>% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("AVISIT") |> + split_cols_by_multivar(vars = c("AVAL", "CHG")) |> analyze_colvars(my_afun, extra_args = list(ref_rowgroup = "V1")) build_table(lyt2, dta_test) diff --git a/vignettes/ard_how_to.Rmd b/vignettes/ard_how_to.Rmd index 5d08cd2cd9..e64b92feac 100644 --- a/vignettes/ard_how_to.Rmd +++ b/vignettes/ard_how_to.Rmd @@ -48,8 +48,8 @@ library(rtables) ADSL <- ex_adsl # Example ADSL dataset # Very simple table -lyt <- basic_table() %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ADSL) @@ -139,9 +139,9 @@ counts_percentage_custom <- function(x) { ) } -lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>% - split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "B: Placebo"))) %>% - analyze(vars = "AGE", afun = mean_sd_custom) %>% +lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") |> + split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "B: Placebo"))) |> + analyze(vars = "AGE", afun = mean_sd_custom) |> analyze(vars = "SEX", afun = counts_percentage_custom) tbl <- build_table(lyt, ex_adsl) @@ -154,11 +154,11 @@ as_result_df(tbl, make_ard = TRUE) Let's add hierarchical row and column splits: ```{r} -lyt <- basic_table() %>% - split_rows_by("STRATA2") %>% - summarize_row_groups() %>% - split_cols_by("ARM") %>% - split_cols_by("STRATA1") %>% +lyt <- basic_table() |> + split_rows_by("STRATA2") |> + summarize_row_groups() |> + split_cols_by("ARM") |> + split_cols_by("STRATA1") |> analyze(c("AGE", "SEX")) tbl <- build_table(lyt, ex_adsl) diff --git a/vignettes/baseline.Rmd b/vignettes/baseline.Rmd index a51d25a78e..df57ccaa4d 100644 --- a/vignettes/baseline.Rmd +++ b/vignettes/baseline.Rmd @@ -41,8 +41,8 @@ For example, lets calculate the average age: ```{r, message=FALSE} library(rtables) -lyt <- basic_table() %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze("AGE") tbl <- build_table(lyt, DM) @@ -53,8 +53,8 @@ and then the difference of the average `AGE` between the placebo arm and the other arms: ```{r} -lyt2 <- basic_table() %>% - split_cols_by("ARM", ref_group = "B: Placebo") %>% +lyt2 <- basic_table() |> + split_cols_by("ARM", ref_group = "B: Placebo") |> analyze("AGE", afun = function(x, .ref_group) { in_rows( "Difference of Averages" = rcell(mean(x) - mean(.ref_group), format = "xx.xx") @@ -73,8 +73,8 @@ In cases where we want cells to be blank in the reference column, and pass `.in_ref_col` as the second argument: ```{r} -lyt3 <- basic_table() %>% - split_cols_by("ARM", ref_group = "B: Placebo") %>% +lyt3 <- basic_table() |> + split_cols_by("ARM", ref_group = "B: Placebo") |> analyze( "AGE", afun = function(x, .ref_group, .in_ref_col) { @@ -87,8 +87,8 @@ lyt3 <- basic_table() %>% tbl3 <- build_table(lyt3, DM) tbl3 -lyt4 <- basic_table() %>% - split_cols_by("ARM", ref_group = "B: Placebo") %>% +lyt4 <- basic_table() |> + split_cols_by("ARM", ref_group = "B: Placebo") |> analyze( "AGE", afun = function(x, .ref_group, .in_ref_col) { @@ -112,9 +112,9 @@ When adding row-splitting the reference data may be represented by the column with or without row splitting. For example: ```{r} -lyt5 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM", ref_group = "B: Placebo") %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% +lyt5 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM", ref_group = "B: Placebo") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> analyze("AGE", afun = function(x, .ref_group, .ref_full, .in_ref_col) { in_rows( "is reference (.in_ref_col)" = rcell(.in_ref_col), diff --git a/vignettes/clinical_trials.Rmd b/vignettes/clinical_trials.Rmd index 03219b27de..90aee95561 100644 --- a/vignettes/clinical_trials.Rmd +++ b/vignettes/clinical_trials.Rmd @@ -78,8 +78,8 @@ rows with the `in_rows()` function: ```{r} ADSL <- ex_adsl # Example ADSL dataset -lyt <- basic_table() %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> analyze(vars = "AGE", afun = function(x) { in_rows( "Mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -94,8 +94,8 @@ tbl Multiple variables can be analyzed in one `analyze()` call: ```{r} -lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> analyze(vars = c("AGE", "BMRKR1"), afun = function(x) { in_rows( "Mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -149,8 +149,8 @@ s_summary(ADSL$SEX) We can now create a commonly used variant of the demographic table: ```{r} -summary_lyt <- basic_table() %>% - split_cols_by(var = "ARM") %>% +summary_lyt <- basic_table() |> + split_cols_by(var = "ARM") |> analyze(c("AGE", "SEX"), afun = s_summary) summary_tbl <- build_table(summary_lyt, ADSL) @@ -160,9 +160,9 @@ summary_tbl Note that `analyze()` can also be called multiple times in sequence: ```{r} -summary_lyt2 <- basic_table() %>% - split_cols_by(var = "ARM") %>% - analyze("AGE", s_summary) %>% +summary_lyt2 <- basic_table() |> + split_cols_by(var = "ARM") |> + analyze("AGE", s_summary) |> analyze("SEX", s_summary) summary_tbl2 <- build_table(summary_lyt2, ADSL) @@ -186,8 +186,8 @@ added by setting the `show_colcounts` argument in `basic_table()` to `TRUE`: ```{r} -summary_lyt3 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD") %>% +summary_lyt3 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARMCD") |> analyze(c("AGE", "SEX"), s_summary) summary_tbl3 <- build_table(summary_lyt3, ADSL) @@ -206,8 +206,8 @@ We will start with a standard table analyzing the variables `AGE` and `BMRKR2` variables: ```{r} -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> analyze(c("AGE", "BMRKR2"), s_summary) tbl <- build_table(lyt, ADSL) @@ -218,9 +218,9 @@ Assume we would like to have this analysis carried out per gender encoded in the row space: ```{r, warning=FALSE} -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX") %>% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX") |> analyze(c("AGE", "BMRKR2"), s_summary) tbl <- build_table(lyt, ADSL) @@ -233,9 +233,9 @@ analysis in order to reduce the number of rows in the table: ```{r, warning=FALSE} ADSL_M_F <- filter(ADSL, SEX %in% c("M", "F")) -lyt2 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX") %>% +lyt2 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX") |> analyze(c("AGE", "BMRKR2"), s_summary) tbl2 <- build_table(lyt2, ADSL_M_F) @@ -254,9 +254,9 @@ vignette. ```{r} -lyt3 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels, child_labels = "visible") %>% +lyt3 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels, child_labels = "visible") |> analyze(c("AGE", "BMRKR2"), s_summary) tbl3 <- build_table(lyt3, ADSL_M_F) @@ -267,7 +267,7 @@ In the table above the labels `M` and `F` are not very descriptive. You can add the full labels as follows: ```{r} -ADSL_M_F_l <- ADSL_M_F %>% +ADSL_M_F_l <- ADSL_M_F |> mutate(lbl_sex = case_when( SEX == "M" ~ "Male", SEX == "F" ~ "Female", @@ -275,9 +275,9 @@ ADSL_M_F_l <- ADSL_M_F %>% SEX == "UNDIFFERENTIATED" ~ "Undifferentiated" )) -lyt4 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels, child_labels = "visible") %>% +lyt4 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels, child_labels = "visible") |> analyze(c("AGE", "BMRKR2"), s_summary) tbl4 <- build_table(lyt4, ADSL_M_F_l) @@ -289,10 +289,10 @@ analysis. To do this the `nested` argument has to be set to `FALSE` in `analyze()` call: ```{r} -lyt5 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels, child_labels = "visible") %>% - analyze("AGE", s_summary, show_labels = "visible") %>% +lyt5 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels, child_labels = "visible") |> + analyze("AGE", s_summary, show_labels = "visible") |> analyze("BMRKR2", s_summary, nested = FALSE, show_labels = "visible") tbl5 <- build_table(lyt5, ADSL_M_F_l) @@ -312,18 +312,18 @@ insert_NAs <- function(x) { } set.seed(1) -ADSL_NA <- ADSL_M_F_l %>% +ADSL_NA <- ADSL_M_F_l |> mutate(AGE = insert_NAs(AGE)) -lyt6 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% +lyt6 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> split_rows_by( "SEX", labels_var = "lbl_sex", split_fun = drop_split_levels, child_labels = "visible" - ) %>% - analyze("AGE", s_summary) %>% + ) |> + analyze("AGE", s_summary) |> analyze("BMRKR2", s_summary, nested = FALSE, show_labels = "visible") tbl6 <- build_table(lyt6, filter(ADSL_NA, SEX %in% c("M", "F"))) @@ -336,11 +336,11 @@ the variables. Groups within rows that are defined by splitting can be summarized with `summarize_row_groups()`, for example: ```{r} -lyt7 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels) %>% - summarize_row_groups() %>% - analyze("AGE", s_summary) %>% +lyt7 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels) |> + summarize_row_groups() |> + analyze("AGE", s_summary) |> analyze("BMRKR2", afun = s_summary, nested = FALSE, show_labels = "visible") tbl7 <- build_table(lyt7, filter(ADSL_NA, SEX %in% c("M", "F"))) @@ -363,16 +363,16 @@ We can recreate this default behavior (count percentage) by defining a as above: ```{r} -lyt8 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels) %>% +lyt8 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels) |> summarize_row_groups(cfun = function(df, labelstr, .N_col, ...) { in_rows( rcell(nrow(df) * c(1, 1 / .N_col), format = "xx (xx.xx%)"), .labels = labelstr ) - }) %>% - analyze("AGE", s_summary) %>% + }) |> + analyze("AGE", s_summary) |> analyze("BEP01FL", afun = s_summary, nested = FALSE, show_labels = "visible") tbl8 <- build_table(lyt8, filter(ADSL_NA, SEX %in% c("M", "F"))) @@ -387,16 +387,16 @@ accept `labelstr` as the second argument which gives the default group label (factor level from splitting) and hence it could be modified: ```{r} -lyt9 <- basic_table() %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels, child_labels = "hidden") %>% +lyt9 <- basic_table() |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", labels_var = "lbl_sex", split_fun = drop_split_levels, child_labels = "hidden") |> summarize_row_groups(cfun = function(df, labelstr, .N_col, ...) { in_rows( rcell(nrow(df) * c(1, 1 / .N_col), format = "xx (xx.xx%)"), .labels = paste0(labelstr, ": count (perc.)") ) - }) %>% - analyze("AGE", s_summary) %>% + }) |> + analyze("AGE", s_summary) |> analyze("BEP01FL", s_summary, nested = FALSE, show_labels = "visible") tbl9 <- build_table(lyt9, filter(ADSL_NA, SEX %in% c("M", "F"))) @@ -419,8 +419,8 @@ directly: Here is an example that demonstrates the reusability of layouts: ```{r} -adsl_lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% +adsl_lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> analyze(c("AGE", "SEX"), afun = s_summary) adsl_lyt @@ -436,7 +436,7 @@ adsl_tbl or for all patients that are older than 18: ```{r} -adsl_f_tbl <- build_table(lyt, ADSL %>% filter(AGE > 18)) +adsl_f_tbl <- build_table(lyt, ADSL |> filter(AGE > 18)) adsl_f_tbl ``` @@ -490,7 +490,7 @@ l.adae <- mapply( FUN = function(id, arm, sex, age) { n_ae <- sample(0:25, 1, prob = if (arm == "ARM A") weightsA else weightsB) i <- sample(seq_len(nrow(lookup)), size = n_ae, replace = TRUE, prob = c(6, rep(1, 10)) / 16) - lookup[i, ] %>% + lookup[i, ] |> mutate( AESEQ = seq_len(n()), USUBJID = id, ARM = arm, SEX = sex, AGE = age @@ -500,13 +500,13 @@ l.adae <- mapply( ) ADAE2 <- do.call(rbind, l.adae) -ADAE2 <- ADAE2 %>% +ADAE2 <- ADAE2 |> mutate( ARM = factor(ARM, levels = c("ARM A", "ARM B")), AEDECOD = as.factor(AEDECOD), AEBODSYS = as.factor(AEBODSYS), AETOXGR = factor(AETOXGR, levels = as.character(1:5)) - ) %>% + ) |> select(USUBJID, ARM, AGE, SEX, AESEQ, AEDECOD, AEBODSYS, AETOXGR) ADAE2 @@ -546,8 +546,8 @@ column. For a list of keyword arguments for the functions passed to We now use the `s_events_patients` summary function in a tabulation: ```{r} -adae_lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% +adae_lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> analyze("USUBJID", s_events_patients) adae_tbl <- build_table(adae_lyt, ADAE2) @@ -581,10 +581,10 @@ mechanism (the number of rows will be used, but no duplicate checking!!!). We next calculate this information per system organ class: ```{r} -adae_soc_lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - analyze("USUBJID", s_events_patients) %>% - split_rows_by("AEBODSYS", child_labels = "visible", nested = FALSE) %>% +adae_soc_lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + analyze("USUBJID", s_events_patients) |> + split_rows_by("AEBODSYS", child_labels = "visible", nested = FALSE) |> summarize_row_groups("USUBJID", cfun = s_events_patients) adae_soc_tbl <- build_table(adae_soc_lyt, ADAE2, alt_counts_df = ADSL2) @@ -596,10 +596,10 @@ default `analyze()` behavior for a factor is to create the count table per level (using `rtab_inner`): ```{r} -adae_soc_lyt2 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1) %>% - summarize_row_groups("USUBJID", cfun = s_events_patients) %>% +adae_soc_lyt2 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1) |> + summarize_row_groups("USUBJID", cfun = s_events_patients) |> analyze("AEDECOD", indent_mod = -1) adae_soc_tbl2 <- build_table(adae_soc_lyt2, ADAE2, alt_counts_df = ADSL2) @@ -634,10 +634,10 @@ table_count_once_per_id(ADAE2) So the desired `AE` table is: ```{r} -adae_soc_lyt3 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1) %>% - summarize_row_groups("USUBJID", cfun = s_events_patients) %>% +adae_soc_lyt3 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1) |> + summarize_row_groups("USUBJID", cfun = s_events_patients) |> analyze("AEDECOD", afun = table_count_once_per_id, show_labels = "hidden", indent_mod = -1) adae_soc_tbl3 <- build_table(adae_soc_lyt3, ADAE2, alt_counts_df = ADSL2) @@ -648,11 +648,11 @@ Note that we are missing the overall summary in the first two rows. This can be added with an initial `analyze()` call. ```{r} -adae_soc_lyt4 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - analyze("USUBJID", afun = s_events_patients) %>% - split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1, section_div = "") %>% - summarize_row_groups("USUBJID", cfun = s_events_patients) %>% +adae_soc_lyt4 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + analyze("USUBJID", afun = s_events_patients) |> + split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1, section_div = "") |> + summarize_row_groups("USUBJID", cfun = s_events_patients) |> analyze("AEDECOD", table_count_once_per_id, show_labels = "hidden", indent_mod = -1) adae_soc_tbl4 <- build_table(adae_soc_lyt4, ADAE2, alt_counts_df = ADSL2) @@ -706,18 +706,18 @@ All of the layouting concepts needed to create this table have already been introduced so far: ```{r} -adae_grade_lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% +adae_grade_lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> analyze( "AETOXGR", afun = table_count_grade_once_per_id, extra_args = list(grade_levels = 1:5), var_labels = "- Any adverse events -", show_labels = "visible" - ) %>% - split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1) %>% - summarize_row_groups(cfun = table_count_grade_once_per_id, format = "xx", indent_mod = 1) %>% - split_rows_by("AEDECOD", child_labels = "visible", indent_mod = -2) %>% + ) |> + split_rows_by("AEBODSYS", child_labels = "visible", indent_mod = 1) |> + summarize_row_groups(cfun = table_count_grade_once_per_id, format = "xx", indent_mod = 1) |> + split_rows_by("AEDECOD", child_labels = "visible", indent_mod = -2) |> analyze( "AETOXGR", afun = table_count_grade_once_per_id, @@ -740,8 +740,8 @@ The response table that we will create here is composed of 3 parts: Let's start with the first part which is fairly simple to derive: ```{r} -ADRS_BESRSPI <- ex_adrs %>% - filter(PARAMCD == "BESRSPI") %>% +ADRS_BESRSPI <- ex_adrs |> + filter(PARAMCD == "BESRSPI") |> mutate( rsp = factor(AVALC %in% c("CR", "PR"), levels = c(TRUE, FALSE), labels = c("Responders", "Non-Responders")), is_rsp = (rsp == "Responders") @@ -756,8 +756,8 @@ s_proportion <- function(x, .N_col) { ) } -rsp_lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% +rsp_lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARMCD", ref_group = "ARM A") |> analyze("rsp", s_proportion, show_labels = "hidden") rsp_tbl <- build_table(rsp_lyt, ADRS_BESRSPI) @@ -827,8 +827,8 @@ s_unstrat_resp <- function(x, .ref_group, .in_ref_col) { } s_unstrat_resp( - x = ADRS_BESRSPI %>% filter(ARM == "A: Drug X") %>% pull(is_rsp), - .ref_group = ADRS_BESRSPI %>% filter(ARM == "B: Placebo") %>% pull(is_rsp), + x = ADRS_BESRSPI |> filter(ARM == "A: Drug X") |> pull(is_rsp), + .ref_group = ADRS_BESRSPI |> filter(ARM == "B: Placebo") |> pull(is_rsp), .in_ref_col = FALSE ) ``` @@ -836,9 +836,9 @@ s_unstrat_resp( Hence we can now add the next vignette to the table: ```{r} -rsp_lyt2 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% - analyze("rsp", s_proportion, show_labels = "hidden") %>% +rsp_lyt2 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARMCD", ref_group = "ARM A") |> + analyze("rsp", s_proportion, show_labels = "hidden") |> analyze( "is_rsp", s_unstrat_resp, show_labels = "visible", @@ -861,7 +861,7 @@ s_prop <- function(df, .N_col) { } s_prop( - df = ADRS_BESRSPI %>% filter(ARM == "A: Drug X", AVALC == "CR"), + df = ADRS_BESRSPI |> filter(ARM == "A: Drug X", AVALC == "CR"), .N_col = sum(ADRS_BESRSPI$ARM == "A: Drug X") ) ``` @@ -869,19 +869,19 @@ s_prop( We can now create the final response table with all three parts: ```{r} -rsp_lyt3 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% - analyze("rsp", s_proportion, show_labels = "hidden") %>% +rsp_lyt3 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARMCD", ref_group = "ARM A") |> + analyze("rsp", s_proportion, show_labels = "hidden") |> analyze( "is_rsp", s_unstrat_resp, show_labels = "visible", var_labels = "Unstratified Response Analysis" - ) %>% + ) |> split_rows_by( var = "AVALC", split_fun = reorder_split_levels(neworder = c("CR", "PR", "SD", "PD", "NE"), drlevels = TRUE), nested = FALSE - ) %>% - summarize_row_groups() %>% + ) |> + summarize_row_groups() |> analyze("AVALC", afun = s_prop) rsp_tbl3 <- build_table(rsp_lyt3, ADRS_BESRSPI) @@ -908,22 +908,22 @@ rsp_label <- function(x) { } -rsp_lyt4 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% - analyze("rsp", s_proportion, show_labels = "hidden") %>% +rsp_lyt4 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARMCD", ref_group = "ARM A") |> + analyze("rsp", s_proportion, show_labels = "hidden") |> analyze( "is_rsp", s_unstrat_resp, show_labels = "visible", var_labels = "Unstratified Response Analysis" - ) %>% + ) |> split_rows_by( var = "AVALC", split_fun = keep_split_levels(c("CR", "PR", "SD", "PD"), reorder = TRUE), nested = FALSE - ) %>% + ) |> summarize_row_groups(cfun = function(df, labelstr, .N_col) { in_rows(nrow(df) * c(1, 1 / .N_col), .formats = "xx (xx.xx%)", .labels = rsp_label(labelstr)) - }) %>% - analyze("AVALC", afun = s_prop) %>% + }) |> + analyze("AVALC", afun = s_prop) |> analyze("AVALC", afun = function(x, .N_col) { in_rows(rcell(sum(x == "NE") * c(1, 1 / .N_col), format = "xx.xx (xx.xx%)"), .labels = rsp_label("NE")) }, nested = FALSE) @@ -958,13 +958,13 @@ the data to be used in the construction of this table. ```{r} library(survival) -adtte <- ex_adaette %>% +adtte <- ex_adaette |> dplyr::filter(PARAMCD == "AETTE2", SAFFL == "Y") # Add censoring to data for example -adtte[adtte$AVAL > 1.0, ] <- adtte[adtte$AVAL > 1.0, ] %>% mutate(AVAL = 1.0, CNSR = 1) +adtte[adtte$AVAL > 1.0, ] <- adtte[adtte$AVAL > 1.0, ] |> mutate(AVAL = 1.0, CNSR = 1) -adtte2 <- adtte %>% +adtte2 <- adtte |> mutate(CNSDTDSC = ifelse(CNSDTDSC == "", "__none__", CNSDTDSC)) ``` @@ -1050,9 +1050,10 @@ summary statistics. ```{r} surv_tbl <- as.data.frame( summary(survfit(Surv(AVAL, CNSR == 0) ~ ACTARM, data = adtte, conf.type = "log-log"))$table -) %>% +) |> + tibble::rownames_to_column("ACTARM") |> dplyr::mutate( - ACTARM = factor(gsub("ACTARM=", "", row.names(.)), levels = levels(adtte$ACTARM)), + ACTARM = factor(gsub("ACTARM=", "", ACTARM), levels = levels(adtte$ACTARM)), ind = FALSE ) @@ -1082,15 +1083,15 @@ Now we are able to use these four analysis functions to build our time to event analysis table. ```{r} -lyt <- basic_table(show_colcounts = TRUE) %>% +lyt <- basic_table(show_colcounts = TRUE) |> ## Column faceting - split_cols_by("ARM", ref_group = "A: Drug X") %>% + split_cols_by("ARM", ref_group = "A: Drug X") |> ## Overall count - analyze("USUBJID", a_count_subjs, show_labels = "hidden") %>% + analyze("USUBJID", a_count_subjs, show_labels = "hidden") |> ## Censored subjects summary - analyze("CNSDTDSC", cnsr_counter, var_labels = "Censored Subjects", show_labels = "visible") %>% + analyze("CNSDTDSC", cnsr_counter, var_labels = "Censored Subjects", show_labels = "visible") |> ## Cox P-H analysis - analyze("ARM", a_cph, extra_args = list(full_cox_fit = cph), show_labels = "hidden") %>% + analyze("ARM", a_cph, extra_args = list(full_cox_fit = cph), show_labels = "hidden") |> ## Time-to-event analysis analyze( "ARM", a_tte, diff --git a/vignettes/col_counts.Rmd b/vignettes/col_counts.Rmd index 8dfc2980c4..b5f7217772 100644 --- a/vignettes/col_counts.Rmd +++ b/vignettes/col_counts.Rmd @@ -45,9 +45,9 @@ passing `show_colcounts = TRUE` to `basic_table` , e.g. ```{r} library(dplyr) library(rtables) -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) %>% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("ARM") |> + split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) |> analyze("AGE") tbl <- build_table(lyt, ex_adsl) @@ -103,12 +103,12 @@ We do this with the new `show_colcounts` argument now accepted by all ```{r} -lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M")), show_colcounts = TRUE - ) %>% + ) |> analyze("AGE") tbl2 <- build_table(lyt2, ex_adsl) @@ -117,9 +117,9 @@ tbl2 ```{r} -lyt3 <- basic_table() %>% - split_cols_by("ARM", show_colcounts = TRUE) %>% - split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) %>% +lyt3 <- basic_table() |> + split_cols_by("ARM", show_colcounts = TRUE) |> + split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M"))) |> analyze("AGE") tbl3 <- build_table(lyt3, ex_adsl) diff --git a/vignettes/custom_appearance.Rmd b/vignettes/custom_appearance.Rmd index eac4b91e9f..5dd1d19f0f 100644 --- a/vignettes/custom_appearance.Rmd +++ b/vignettes/custom_appearance.Rmd @@ -71,7 +71,7 @@ In the following we show two simplified examples that use `align` and ```{r} # In rcell we use align. -lyt <- basic_table() %>% +lyt <- basic_table() |> analyze("AGE", function(x) { in_rows( left = rcell("l", align = "left"), @@ -87,7 +87,7 @@ tbl ```{r} # In in_rows, we use .aligns. This can either set the general value or the # single values (see NB). -lyt2 <- basic_table() %>% +lyt2 <- basic_table() |> analyze("AGE", function(x) { in_rows( left = rcell("l"), @@ -105,9 +105,9 @@ These concepts can be well applied to any clinical table as shown in the following, more complex, example. ```{r} -lyt3 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt3 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(c("AGE", "STRATA1"), function(x) { if (is.numeric(x)) { in_rows( @@ -139,10 +139,10 @@ automatically added \emph{only in the case of} `label_pos = Within the layout initializer: ```{r} -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("STRATA1") %>% - analyze("AGE") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("STRATA1") |> + analyze("AGE") |> append_topleft("New top_left material here") build_table(lyt, DM) @@ -152,10 +152,10 @@ Specify label position using the `split_rows` function. Notice the position of `STRATA1` and `SEX`. ```{r} -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("STRATA1", label_pos = "topleft") %>% - split_rows_by("SEX", label_pos = "topleft") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("STRATA1", label_pos = "topleft") |> + split_rows_by("SEX", label_pos = "topleft") |> analyze("AGE") build_table(lyt, DM) @@ -164,9 +164,9 @@ build_table(lyt, DM) Post-processing using the `top_left()` function: ```{r} -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(c("AGE", "STRATA1"), function(x) { if (is.numeric(x)) { in_rows( @@ -179,7 +179,7 @@ lyt <- basic_table() %>% } else { stop("Unsupported type") } - }, show_labels = "visible", na_str = "NE") %>% + }, show_labels = "visible", na_str = "NE") |> build_table(ex_adsl) # Adding top-left material @@ -199,7 +199,7 @@ with `table_inset()`. Using the layout initializer: ```{r} -lyt <- basic_table(inset = 5) %>% +lyt <- basic_table(inset = 5) |> analyze("AGE") build_table(lyt, DM) @@ -209,7 +209,7 @@ Using the post-processing function: Without inset - ```{r} -lyt <- basic_table() %>% +lyt <- basic_table() |> analyze("AGE") tbl <- build_table(lyt, DM) @@ -241,8 +241,8 @@ analysisfun <- function(x, ...) { lyt <- basic_table( title = "Title says Whaaaat", subtitles = "Oh, ok.", main_footer = "ha HA! Footer!", prov_footer = "provenaaaaance" -) %>% - split_cols_by("ARM") %>% +) |> + split_cols_by("ARM") |> analyze("AGE", afun = analysisfun) result <- build_table(lyt, ex_adsl) @@ -278,9 +278,9 @@ when: Below, we replace the default line with "=". ```{r} -tbl <- basic_table() %>% - split_cols_by("Species") %>% - add_colcounts() %>% +tbl <- basic_table() |> + split_cols_by("Species") |> + add_colcounts() |> analyze(c("Sepal.Length", "Petal.Width"), function(x) { in_rows( mean_sd = c(mean(x), sd(x)), @@ -289,7 +289,7 @@ tbl <- basic_table() %>% .formats = c("xx.xx (xx.xx)", "xx.xxx", "xx.x - xx.x"), .labels = c("Mean (sd)", "Variance", "Min - Max") ) - }) %>% + }) |> build_table(iris, hsep = "=") tbl ``` @@ -304,8 +304,8 @@ at the end of the table is never printed. Below, a "+" is repeated and used as a section divider. ```{r} -lyt <- basic_table() %>% - split_cols_by("Species") %>% +lyt <- basic_table() |> + split_cols_by("Species") |> analyze(head(names(iris), -1), afun = function(x) { list( "mean / sd" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -319,8 +319,8 @@ build_table(lyt, iris) Section dividers can be set to " " to create a blank line. ```{r} -lyt <- basic_table() %>% - split_cols_by("Species") %>% +lyt <- basic_table() |> + split_cols_by("Species") |> analyze(head(names(iris), -1), afun = function(x) { list( "mean / sd" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"), @@ -336,10 +336,10 @@ splits. However, only one will be printed if they "pile up" next to each other. ```{r} -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("RACE", section_div = "=") %>% - split_rows_by("STRATA1", section_div = "~") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("RACE", section_div = "=") |> + split_rows_by("STRATA1", section_div = "~") |> analyze("AGE", mean, var_labels = "Age", format = "xx.xx") build_table(lyt, DM) @@ -360,11 +360,11 @@ basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% - split_rows_by("STRATA1") %>% - analyze("AGE", mean, format = "xx.x") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> + split_rows_by("STRATA1") |> + analyze("AGE", mean, format = "xx.x") |> build_table(DM) ``` @@ -375,11 +375,11 @@ basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", indent_mod = 3) %>% - split_rows_by("STRATA1", indent_mod = 5) %>% - analyze("AGE", mean, format = "xx.x") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX", indent_mod = 3) |> + split_rows_by("STRATA1", indent_mod = 5) |> + analyze("AGE", mean, format = "xx.x") |> build_table(DM) ``` @@ -401,10 +401,10 @@ content rows but we cannot hide or move the content rows. Notice the placement of the "AGE" label in this example: ```{r} -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels, child_labels = "visible") %>% - split_rows_by("STRATA1") %>% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels, child_labels = "visible") |> + split_rows_by("STRATA1") |> analyze("AGE", mean, show_labels = "default") build_table(lyt, DM) @@ -416,10 +416,10 @@ nesting. Override this by setting the `show_labels` argument as "visible". ```{r} -lyt2 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels, child_labels = "hidden") %>% - split_rows_by("STRATA1") %>% +lyt2 <- basic_table(show_colcounts = TRUE) |> + split_cols_by(var = "ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels, child_labels = "hidden") |> + split_rows_by("STRATA1") |> analyze("AGE", mean, show_labels = "visible") build_table(lyt2, DM) @@ -439,11 +439,11 @@ basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels, label_pos = "visible") %>% - split_rows_by("STRATA1", label_pos = "hidden") %>% - analyze("AGE", mean, format = "xx.x") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels, label_pos = "visible") |> + split_rows_by("STRATA1", label_pos = "hidden") |> + analyze("AGE", mean, format = "xx.x") |> build_table(DM) ``` @@ -455,11 +455,11 @@ basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels, label_pos = "topleft") %>% - split_rows_by("STRATA1", label_pos = "hidden") %>% - analyze("AGE", mean, format = "xx.x") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels, label_pos = "topleft") |> + split_rows_by("STRATA1", label_pos = "hidden") |> + analyze("AGE", mean, format = "xx.x") |> build_table(DM) ``` @@ -474,8 +474,8 @@ table has very wide contents in several cells, labels, and titles/footers. ```{r} -trimmed_data <- ex_adsl %>% - filter(SEX %in% c("M", "F")) %>% +trimmed_data <- ex_adsl |> + filter(SEX %in% c("M", "F")) |> filter(RACE %in% levels(RACE)[1:2]) levels(trimmed_data$ARM)[1] <- "Incredibly long column name to be wrapped" @@ -486,14 +486,14 @@ wide_tbl <- basic_table( subtitles = "Subtitle that is also long and also needs to be wrapped to a smaller width", main_footer = "Footnote that is wider than expected for this table.", prov_footer = "Provenance footer material that is also wider than expected for this table." -) %>% - split_cols_by("ARM") %>% - split_rows_by("RACE", split_fun = drop_split_levels) %>% +) |> + split_cols_by("ARM") |> + split_rows_by("RACE", split_fun = drop_split_levels) |> analyze( c("AGE", "EOSDY"), na_str = "Very long cell contents to_be_wrapped_and_splitted", inclNAs = TRUE - ) %>% + ) |> build_table(trimmed_data) wide_tbl diff --git a/vignettes/dev-guide/dg_notes.Rmd b/vignettes/dev-guide/dg_notes.Rmd index 73079c9f17..033f1b6d0d 100644 --- a/vignettes/dev-guide/dg_notes.Rmd +++ b/vignettes/dev-guide/dg_notes.Rmd @@ -72,9 +72,9 @@ getClass("VTableTree") Always check the constructors after finding the classes. In the above case for example, the `DataRow` and `ContentRow` share the constructor, so we do not need to add identical getter and setters for these two classes but only for the virtual class `TableRow`. Different is the story for `LabelRow` which needs to be handle differently. Now, to understand why only these two have this feature, lets see the structure of a table built with section dividers: ```{r} -lyt <- basic_table() %>% - split_rows_by("ARM", section_div = "+") %>% - split_rows_by("STRATA1", section_div = "") %>% +lyt <- basic_table() |> + split_rows_by("ARM", section_div = "+") |> + split_rows_by("STRATA1", section_div = "") |> analyze("AGE", afun = function(x) list("Mean" = mean(x), "Standard deviation" = sd(x)), format = list("Mean" = "xx.", "Standard deviation" = "xx."), diff --git a/vignettes/dev-guide/dg_printing.Rmd b/vignettes/dev-guide/dg_printing.Rmd index e0bca1b877..17cc34c629 100644 --- a/vignettes/dev-guide/dg_printing.Rmd +++ b/vignettes/dev-guide/dg_printing.Rmd @@ -28,12 +28,12 @@ Lets track down what is going under the hood when a standard table is printed. T ```{r} library(rtables) library(dplyr) -lyt <- basic_table() %>% - split_rows_by("SEX", split_fun = keep_split_levels(c("F", "M"))) %>% - split_cols_by("ARM") %>% - analyze("BMRKR1") %>% +lyt <- basic_table() |> + split_rows_by("SEX", split_fun = keep_split_levels(c("F", "M"))) |> + split_cols_by("ARM") |> + analyze("BMRKR1") |> print() -tbl <- build_table(lyt, ex_adsl) %>% +tbl <- build_table(lyt, ex_adsl) |> print() ``` @@ -63,11 +63,11 @@ methods(class = "PreDataTableLayouts") Now, lets see the same for our result table `tbl`: ```{r} -class(tbl) %>% print() +class(tbl) |> print() -getClass("TableTree") %>% print() # Main object representing a table in {rtables} +getClass("TableTree") |> print() # Main object representing a table in {rtables} -methods(class = "TableTree") %>% print() # more than 70 methods but no print method +methods(class = "TableTree") |> print() # more than 70 methods but no print method ``` Again, the class itself has only the `show` method. Nonetheless, if you search for `VTableTree"` you will find the `print` method for the `TableTree` class. This is because `VTableTree` is a virtual class that is inherited by `TableTree` and is almost identical to the `show` method for `TableTree` objects. All the different statements in this case (`show` or `print`) do the same thing, i.e. they call `toString` and `cat` on the object. Hence, we know that every table is printed by `toString` with `\n` as separator for different lines so that `cat` renders it in its final format. diff --git a/vignettes/dev-guide/dg_split_machinery.Rmd b/vignettes/dev-guide/dg_split_machinery.Rmd index 9b7ffb103a..0fb3142e98 100644 --- a/vignettes/dev-guide/dg_split_machinery.Rmd +++ b/vignettes/dev-guide/dg_split_machinery.Rmd @@ -42,7 +42,7 @@ The split machinery is so fundamental to `rtables` that relevant functions like ```{r, message=FALSE} library(rtables) # debugonce(rtables:::do_split) # Uncomment me to enter the function!!! -basic_table() %>% +basic_table() |> build_table(DM) ``` @@ -425,18 +425,18 @@ library(rtables) library(dplyr) # This filter is added to avoid having too many calls to do_split -DM_tmp <- DM %>% - filter(ARM %in% names(table(DM$ARM)[1:2])) %>% # limit to two - filter(SEX %in% c("M", "F")) %>% # limit to two +DM_tmp <- DM |> + filter(ARM %in% names(table(DM$ARM)[1:2])) |> # limit to two + filter(SEX %in% c("M", "F")) |> # limit to two mutate(SEX = factor(SEX), ARM = factor(ARM)) # to drop unused levels # debug(rtables:::do_split) -lyt <- basic_table() %>% - split_rows_by("ARM") %>% - split_rows_by("SEX") %>% +lyt <- basic_table() |> + split_rows_by("ARM") |> + split_rows_by("SEX") |> analyze("BMRKR1") # analyze() is needed for the table to have non-label rows -lyt %>% +lyt |> build_table(DM_tmp) # undebug(rtables:::do_split) ``` @@ -564,9 +564,9 @@ We start by examining a split function that is already defined in `rtables`. Its ```{r, message=FALSE} library(rtables) # debug(rtables:::do_split) # uncomment to see into the main split function -basic_table() %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% - analyze("BMRKR1") %>% +basic_table() |> + split_rows_by("SEX", split_fun = drop_split_levels) |> + analyze("BMRKR1") |> build_table(DM) # undebug(rtables:::do_split) @@ -611,11 +611,11 @@ Now we will create a custom split function. Firstly, we will see how the system # rtables 0.6.2 # Table call with only the function changing simple_table <- function(DM, f) { - lyt <- basic_table() %>% - split_rows_by("ARM", split_fun = f) %>% + lyt <- basic_table() |> + split_rows_by("ARM", split_fun = f) |> analyze("BMRKR1") - lyt %>% + lyt |> build_table(DM) } # First round will fail because there are unused arguments @@ -717,19 +717,19 @@ fnc_tmp <- function(innervar) { # Exploring trim_levels_in_facets (check its for } } -basic_table() %>% - split_rows_by("ARM") %>% - split_rows_by("STRATA1") %>% +basic_table() |> + split_rows_by("ARM") |> + split_rows_by("STRATA1") |> split_rows_by_cuts("AGE", cuts = c(0, 50, 100), cutlabels = c("young", "old") - ) %>% + ) |> split_rows_by("SEX", split_fun = make_split_fun( pre = list(drop_facet_levels), # This is dropping the SEX levels (AGE is upper level) core_split = browsing_f, post = list(fnc_tmp("AGE")) # To drop these we should use a split_fun in the above level - )) %>% - summarize_row_groups() %>% + )) |> + summarize_row_groups() |> build_table(DM) ``` @@ -773,17 +773,17 @@ custom_mean_var <- function(var) { DM_ageNA <- DM DM_ageNA$AGE[1] <- NA -basic_table() %>% - split_rows_by("ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% +basic_table() |> + split_rows_by("ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> summarize_row_groups( cfun = custom_mean_var("AGE"), extra_args = list(na.rm = TRUE), format = "xx.x", label_fstr = "label %s" - ) %>% + ) |> # content_extra_args, c_extra_args are different slots!! (xxx) - split_rows_by("STRATA1", split_fun = keep_split_levels("A")) %>% - analyze("AGE") %>% # check with the extra_args (xxx) + split_rows_by("STRATA1", split_fun = keep_split_levels("A")) |> + analyze("AGE") |> # check with the extra_args (xxx) build_table(DM_ageNA) # You can pass extra_args down to other splits. It is possible this will not not # work. Should it? That is why extra_args lives only in splits (xxx) check if it works @@ -801,10 +801,10 @@ my_split_fun <- function(df, spl, .spl_context, ...) { drop_split_levels(df, spl) } # does not work -basic_table() %>% - split_rows_by("ARM") %>% - split_rows_by("SEX", split_fun = my_split_fun) %>% - analyze("AGE", inclNAs = TRUE, afun = mean) %>% # include_NAs is set FALSE +basic_table() |> + split_rows_by("ARM") |> + split_rows_by("SEX", split_fun = my_split_fun) |> + analyze("AGE", inclNAs = TRUE, afun = mean) |> # include_NAs is set FALSE build_table(DM_ageNA) # extra_args is in available in cols but not in rows, because different columns # may need it for different col space. Row-wise it seems not necessary. @@ -854,15 +854,15 @@ trace( ) # We want also to take a look at the following: debugonce(rtables:::.apply_split_inner) -lyt <- basic_table() %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> split_rows_by_multivar(c("BMRKR1", "BMRKR1"), varlabels = c("SD", "MEAN") - ) %>% + ) |> split_rows_by("COUNTRY", split_fun = keep_split_levels("PAK") - ) %>% # xxx for #690 #691 - summarize_row_groups() %>% + ) |> # xxx for #690 #691 + summarize_row_groups() |> analyze(c("AGE", "SEX")) build_table(lyt, DM) @@ -890,14 +890,14 @@ cutfun <- function(x) { cutpoints } -tbl <- basic_table(show_colcounts = TRUE) %>% - split_rows_by("ARM", split_fun = drop_and_remove_levels(c("B: Placebo", "C: Combination"))) %>% - split_rows_by("STRATA1") %>% - split_rows_by_cutfun("AGE", cutfun = cutfun) %>% +tbl <- basic_table(show_colcounts = TRUE) |> + split_rows_by("ARM", split_fun = drop_and_remove_levels(c("B: Placebo", "C: Combination"))) |> + split_rows_by("STRATA1") |> + split_rows_by_cutfun("AGE", cutfun = cutfun) |> # split_rows_by_cuts("AGE", cuts = c(0, 50, 100), - # cutlabels = c("young", "old")) %>% # Works the same - split_rows_by("SEX", split_fun = drop_split_levels) %>% - summarize_row_groups() %>% # This is degenerate!!! + # cutlabels = c("young", "old")) |> # Works the same + split_rows_by("SEX", split_fun = drop_split_levels) |> + summarize_row_groups() |> # This is degenerate!!! build_table(DM) tbl @@ -949,15 +949,15 @@ gen_split <- make_split_fun( post = list(drop_empties) ) -tbl <- basic_table(show_colcounts = TRUE) %>% - split_rows_by("ARM", split_fun = keep_split_levels(c("A: Drug X"))) %>% - split_rows_by("STRATA1") %>% - split_rows_by("AGE", split_fun = gen_split) %>% - analyze("SEX") %>% # It is the last step!! No need of BMRKR1 right? +tbl <- basic_table(show_colcounts = TRUE) |> + split_rows_by("ARM", split_fun = keep_split_levels(c("A: Drug X"))) |> + split_rows_by("STRATA1") |> + split_rows_by("AGE", split_fun = gen_split) |> + analyze("SEX") |> # It is the last step!! No need of BMRKR1 right? # split_rows_by("SEX", split_fun = drop_split_levels, - # child_labels = "hidden") %>% # close issue #689. would it work for + # child_labels = "hidden") |> # close issue #689. would it work for # analyze_colvars? probably (xxx) - # analyze("BMRKR1", afun = my_count_afun) %>% # This is NOT degenerate!!! BMRKR1 is only placeholder + # analyze("BMRKR1", afun = my_count_afun) |> # This is NOT degenerate!!! BMRKR1 is only placeholder build_table(DM) tbl @@ -968,16 +968,16 @@ Alternatively, we could choose to prune these rows out with `prune_table`! ```{r} # rtables 0.6.2 -tbl <- basic_table(show_colcounts = TRUE) %>% - split_rows_by("ARM", split_fun = keep_split_levels(c("A: Drug X"))) %>% - split_rows_by("STRATA1") %>% +tbl <- basic_table(show_colcounts = TRUE) |> + split_rows_by("ARM", split_fun = keep_split_levels(c("A: Drug X"))) |> + split_rows_by("STRATA1") |> split_rows_by_cuts( "AGE", cuts = c(0, 50, 100), cutlabels = c("young", "old") - ) %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% - summarize_row_groups() %>% # This is degenerate!!! # we keep it until #689 + ) |> + split_rows_by("SEX", split_fun = drop_split_levels) |> + summarize_row_groups() |> # This is degenerate!!! # we keep it until #689 build_table(DM) tbl diff --git a/vignettes/dev-guide/dg_table_hierarchy.Rmd b/vignettes/dev-guide/dg_table_hierarchy.Rmd index 8b0d342c21..89b7ebd6e4 100644 --- a/vignettes/dev-guide/dg_table_hierarchy.Rmd +++ b/vignettes/dev-guide/dg_table_hierarchy.Rmd @@ -71,8 +71,8 @@ You'll notice there are classes that fall under "Extends". The classes contained ```{r} -lyt <- basic_table(title = "big title") %>% - split_rows_by("SEX", page_by = TRUE) %>% +lyt <- basic_table(title = "big title") |> + split_rows_by("SEX", page_by = TRUE) |> analyze("AGE") tt <- build_table(lyt, DM) diff --git a/vignettes/dev-guide/dg_tabulation.Rmd b/vignettes/dev-guide/dg_tabulation.Rmd index ead790cfa3..3a4832c558 100644 --- a/vignettes/dev-guide/dg_tabulation.Rmd +++ b/vignettes/dev-guide/dg_tabulation.Rmd @@ -35,16 +35,16 @@ library(rtables) debugonce(build_table) # A very simple layout -lyt <- basic_table() %>% - split_rows_by("STRATA1") %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_rows_by("STRATA1") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> + split_cols_by("ARM") |> analyze("BMRKR1") # lyt must be a PreDataTableLayouts object is(lyt, "PreDataTableLayouts") -lyt %>% build_table(DM) +lyt |> build_table(DM) ``` Now let's look within our `build_table` call. After the initial check that the layout is a pre-data table layout, it checks if the column layout is defined (`clayout` accessor), i.e. it does not have any column split. If that is the case, a `All obs` column is added automatically with all observations. After this, there are a couple of defensive programming calls that do checks and transformations as we finally have the data. These can be divided into two categories: those that mainly concern the layout, which are defined as generics, and those that concern the data, which are instead a function as they are not dependent on the layout class. Indeed, the layout is structured and can be divided into `clayout` and `rlayout` (column and row layout). The first one is used to create `cinfo`, which is the general object and container of the column splits and information. The second one contains the obligatory all data split, i.e. the root split (accessible with `root_spl`), and the row splits' vectors which are iterative splits in the row space. In the following, we consider the initial checks and defensive programming. @@ -113,10 +113,10 @@ Going back to `build_table`, you will see that the row layout is actually a list ```{r, eval=FALSE} # rtables 0.6.2 # A very simple layout -lyt <- basic_table() %>% - split_rows_by("STRATA1") %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% - split_cols_by("ARM") %>% +lyt <- basic_table() |> + split_rows_by("STRATA1") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> + split_cols_by("ARM") |> analyze("BMRKR1") rlyt <- rtables:::rlayout(lyt) diff --git a/vignettes/example_analysis_coxreg.Rmd b/vignettes/example_analysis_coxreg.Rmd index fd74fbabda..f4ead8acce 100644 --- a/vignettes/example_analysis_coxreg.Rmd +++ b/vignettes/example_analysis_coxreg.Rmd @@ -45,12 +45,12 @@ We prepare the data as needed to observe the desired effects in our summary tabl ```{r} adtte <- ex_adtte -anl <- adtte %>% - dplyr::filter(PARAMCD == "OS") %>% - dplyr::filter(ARM %in% c("A: Drug X", "B: Placebo")) %>% - dplyr::filter(RACE %in% c("ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE")) %>% - dplyr::mutate(RACE = droplevels(RACE)) %>% - dplyr::mutate(ARM = droplevels(stats::relevel(ARM, "B: Placebo"))) %>% +anl <- adtte |> + dplyr::filter(PARAMCD == "OS") |> + dplyr::filter(ARM %in% c("A: Drug X", "B: Placebo")) |> + dplyr::filter(RACE %in% c("ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE")) |> + dplyr::mutate(RACE = droplevels(RACE)) |> + dplyr::mutate(ARM = droplevels(stats::relevel(ARM, "B: Placebo"))) |> dplyr::mutate(EVENT = 1 - CNSR) ``` @@ -355,7 +355,7 @@ Following this row split, we use `summarize_row_groups` with `a_cox_summary` as The last part of our table is the covariate interaction effects. We use `analyze_colvars` with `a_cox_summary` as `afun`, and again inherit `extra_args` from the column split. Using an `rtables` "analyze" function generates data rows, with one row corresponding to each covariate level (or median value, for numeric covariates), nested under the content row (main effect) for that same covariate. ```{r} -lyt <- basic_table() %>% +lyt <- basic_table() |> ## Column split: one column for each statistic split_cols_by_multivar( vars = rep("STUDYID", length(my_stats)), @@ -365,21 +365,21 @@ lyt <- basic_table() %>% format = my_formats, cache_env = ny_cache_env ) - ) %>% + ) |> ## Create content row for treatment effect - summarize_row_groups(cfun = a_cox_summary) %>% + summarize_row_groups(cfun = a_cox_summary) |> ## Row split: one content row for each covariate split_rows_by_multivar( vars = my_covs, varlabels = my_cov_labs, split_label = "Covariate:", indent_mod = -1 ## Align split label left - ) %>% + ) |> ## Create content rows for covariate main effects summarize_row_groups( cfun = a_cox_summary, extra_args = list(cov_main = TRUE) - ) %>% + ) |> ## Create data rows for covariate interaction effects analyze_colvars(afun = a_cox_summary) ``` diff --git a/vignettes/format_precedence.Rmd b/vignettes/format_precedence.Rmd index 90413f2e1f..315217e142 100644 --- a/vignettes/format_precedence.Rmd +++ b/vignettes/format_precedence.Rmd @@ -70,9 +70,9 @@ given table object. For a simple illustration, consider the following example: ```{r} -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(vars = "AGE", afun = mean) adsl_analyzed <- build_table(lyt, ADSL) @@ -113,8 +113,8 @@ output of the analysis function. In such a case, the default format is applied. ```{r} -lyt0 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt0 <- basic_table() |> + split_cols_by("ARM") |> analyze(vars = "AGE", afun = mean) build_table(lyt0, ADSL) @@ -129,16 +129,16 @@ previously mentioned, this is the most specific place where the format can be specified by the user. ```{r} -lyt1 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt1 <- basic_table() |> + split_cols_by("ARM") |> analyze(vars = "AGE", afun = function(x) { rcell(mean(x), format = "xx.xx", label = "Mean") }) build_table(lyt1, ADSL) -lyt1a <- basic_table() %>% - split_cols_by("ARM") %>% +lyt1a <- basic_table() |> + split_cols_by("ARM") |> analyze(vars = "AGE", afun = function(x) { in_rows( "Mean" = rcell(mean(x)), @@ -159,8 +159,8 @@ values), which indicates that the precedence rules described above are still in place. ```{r} -lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> analyze(vars = "AGE", afun = function(x) { in_rows( "Mean" = rcell(mean(x), format = "xx.xxx"), @@ -179,8 +179,8 @@ the most specific format for that cell is the one defined at its innermost parent table split (if any). ```{r} -lyt3 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt3 <- basic_table() |> + split_cols_by("ARM") |> analyze(vars = "AGE", mean, format = "xx.x") build_table(lyt3, ADSL) @@ -191,8 +191,8 @@ format is ignored for this cell since the cell format is more specific and therefore takes precedence. ```{r} -lyt4 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt4 <- basic_table() |> + split_cols_by("ARM") |> analyze( vars = "AGE", afun = function(x) { rcell(mean(x), format = "xx.xx", label = "Mean") @@ -202,8 +202,8 @@ lyt4 <- basic_table() %>% build_table(lyt4, ADSL) -lyt4a <- basic_table() %>% - split_cols_by("ARM") %>% +lyt4a <- basic_table() |> + split_cols_by("ARM") |> analyze( vars = "AGE", afun = function(x) { in_rows( @@ -223,8 +223,8 @@ partial inheritance. That is, only `SD` cells inherit the parent table's format while the `Mean` cells do not. ```{r} -lyt5 <- basic_table() %>% - split_cols_by("ARM") %>% +lyt5 <- basic_table() |> + split_cols_by("ARM") |> analyze( vars = "AGE", afun = function(x) { in_rows( @@ -243,9 +243,9 @@ build_table(lyt5, ADSL) Consider the following layout and the resulting table created: ```{r} -lyt6 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt6 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(vars = "AGE", afun = mean, format = "xx.xx") build_table(lyt6, ADSL) @@ -270,18 +270,18 @@ string by means of the `format_na_str` parameter in `rcell()` or `.format_na_str` parameter in `in_rows()`. ```{r} -lyt7 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt7 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(vars = "AGE", afun = function(x) { rcell(mean(x), format = "xx.xx", label = "Mean", format_na_str = "") }) build_table(lyt7, ADSL) -lyt7a <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt7a <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(vars = "AGE", afun = function(x) { in_rows( "Mean" = rcell(mean(x), format = "xx.xx"), @@ -302,9 +302,9 @@ specified cell specific values), which means that the precedence rules described above are still in place. ```{r} -lyt8 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt8 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(vars = "AGE", afun = function(x) { in_rows( "Mean" = rcell(mean(x), format = "xx.xx", format_na_str = ""), @@ -324,9 +324,9 @@ string has been specified by the user for a cell, the most specific table split (if any). ```{r} -lyt9 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt9 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze(vars = "AGE", mean, format = "xx.xx", na_str = "not available") build_table(lyt9, ADSL) @@ -338,9 +338,9 @@ this cell as the cell level format is more specific and therefore takes precedence. ```{r} -lyt10 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt10 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze( vars = "AGE", afun = function(x) { rcell(mean(x), format = "xx.xx", label = "Mean", format_na_str = "") @@ -350,9 +350,9 @@ lyt10 <- basic_table() %>% build_table(lyt10, ADSL) -lyt10a <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt10a <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze( vars = "AGE", afun = function(x) { in_rows( @@ -373,9 +373,9 @@ partial inheritance of NA strings. That is, only `SD` cells inherit the parent table's `NA` string, while the `Mean` cells do not. ```{r} -lyt11 <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX") %>% +lyt11 <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX") |> analyze( vars = "AGE", afun = function(x) { in_rows( diff --git a/vignettes/guided_intermediate_translating_shells.Rmd b/vignettes/guided_intermediate_translating_shells.Rmd index d028a87e0b..7641bd26a7 100644 --- a/vignettes/guided_intermediate_translating_shells.Rmd +++ b/vignettes/guided_intermediate_translating_shells.Rmd @@ -76,8 +76,8 @@ knitr::opts_chunk$set(comment = "") ```{r, echo = FALSE, result = "asis"} -adsl <- ex_adsl %>% - filter(SEX %in% c("M", "F") & RACE %in% c("ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE")) %>% +adsl <- ex_adsl |> + filter(SEX %in% c("M", "F") & RACE %in% c("ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE")) |> mutate( BMEASIFL = factor(as.character(BMEASIFL), levels = c("Y", "N"), @@ -97,24 +97,24 @@ adsl <- ex_adsl %>% lyt <- basic_table( title = "Subject Response by Race and Sex; Treated Subjects", show_colcounts = TRUE -) %>% - split_cols_by("STRATA1", split_fun = keep_split_levels(only = c("A", "B"))) %>% - split_cols_by("ARM", split_fun = keep_split_levels(only = c("A: Drug X", "B: Placebo"))) %>% - analyze("BMEASIFL", afun = counts_wpcts, var_labels = "All Patients", show_labels = "visible") %>% +) |> + split_cols_by("STRATA1", split_fun = keep_split_levels(only = c("A", "B"))) |> + split_cols_by("ARM", split_fun = keep_split_levels(only = c("A: Drug X", "B: Placebo"))) |> + analyze("BMEASIFL", afun = counts_wpcts, var_labels = "All Patients", show_labels = "visible") |> split_rows_by( var = "RACE", label_pos = "topleft", split_fun = keep_split_levels(only = c("Asian", "Black", "White")) - ) %>% + ) |> split_rows_by( var = "SEX", label_pos = "topleft", split_fun = keep_split_levels(only = c("Male", "Female")) - ) %>% + ) |> summarize_row_groups( var = "SEX", format = "xx" - ) %>% + ) |> analyze( vars = "BMEASIFL", afun = counts_wpcts @@ -191,7 +191,7 @@ the outermost faceting first: ```{r} lyt_cols <- basic_table() |> - split_cols_by("STRATA1", split_fun = keep_split_levels(only = c("A", "B"))) %>% + split_cols_by("STRATA1", split_fun = keep_split_levels(only = c("A", "B"))) |> split_cols_by("ARM", split_fun = keep_split_levels(only = c("A: Drug X", "B: Placebo"))) build_table(lyt_cols, adsl) @@ -203,7 +203,7 @@ the relevant `split_cols_by` call: ```{r} lyt_cols <- basic_table() |> - split_cols_by("STRATA1", split_fun = keep_split_levels(only = c("A", "B"))) %>% + split_cols_by("STRATA1", split_fun = keep_split_levels(only = c("A", "B"))) |> split_cols_by("ARM", split_fun = keep_split_levels(only = c("A: Drug X", "B: Placebo")), show_colcounts = TRUE diff --git a/vignettes/introspecting_tables.Rmd b/vignettes/introspecting_tables.Rmd index 98ca6e6435..b66a6d37e7 100644 --- a/vignettes/introspecting_tables.Rmd +++ b/vignettes/introspecting_tables.Rmd @@ -41,12 +41,12 @@ library(dplyr) First, let's set up a simple table. ```{r} -lyt <- basic_table() %>% - split_cols_by("ARMCD", show_colcounts = TRUE, colcount_format = "N=xx") %>% - split_cols_by("STRATA2", show_colcounts = TRUE) %>% - split_rows_by("STRATA1") %>% - add_overall_col("All") %>% - summarize_row_groups() %>% +lyt <- basic_table() |> + split_cols_by("ARMCD", show_colcounts = TRUE, colcount_format = "N=xx") |> + split_cols_by("STRATA2", show_colcounts = TRUE) |> + split_rows_by("STRATA1") |> + add_overall_col("All") |> + summarize_row_groups() |> analyze("AGE", afun = max, format = "xx.x") tbl <- build_table(lyt, ex_adsl) diff --git a/vignettes/rtables.Rmd b/vignettes/rtables.Rmd index 1eb3e897ff..577c222ffe 100644 --- a/vignettes/rtables.Rmd +++ b/vignettes/rtables.Rmd @@ -86,7 +86,7 @@ df <- tibble( gender = factor(sample(c("Female", "Male"), n, replace = TRUE), levels = c("Female", "Male")), handed = factor(sample(c("Left", "Right"), n, prob = c(.6, .4), replace = TRUE), levels = c("Left", "Right")), age = rchisq(n, 30) + 10 -) %>% mutate( +) |> mutate( weight = 35 * rnorm(n, sd = .5) + ifelse(gender == "Female", 140, 180) ) @@ -102,13 +102,13 @@ information of `df` below. The aim of this vignette is to build the following table step by step: ```{r, echo=FALSE} -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% - summarize_row_groups() %>% - split_rows_by("handed") %>% - summarize_row_groups() %>% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> + summarize_row_groups() |> + split_rows_by("handed") |> + summarize_row_groups() |> analyze("age", afun = mean, format = "xx.xx") tbl <- build_table(lyt, df) @@ -157,7 +157,7 @@ representing all data. Analyzing a variable is one way of adding a row: ```{r} -lyt <- basic_table() %>% +lyt <- basic_table() |> analyze("age", mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -203,8 +203,8 @@ We will now add more structure to the columns by adding a column split based on the factor variable `arm`: ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% +lyt <- basic_table() |> + split_cols_by("arm") |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -222,9 +222,9 @@ add a non-nested split. Here we splitting each arm further by the gender: ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% +lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by("gender") |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -246,10 +246,10 @@ data row. We will add more row structure by stratifying the mean analysis by country (i.e. adding a split in the row space): ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% +lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -270,11 +270,11 @@ of pages during rendering. We do this via 'page by splits', which are declared via `page_by = TRUE` within a call to `split_rows_by`: ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country", page_by = TRUE) %>% - split_rows_by("handed") %>% +lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country", page_by = TRUE) |> + split_rows_by("handed") |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -304,11 +304,11 @@ the count (`nrows()`) and percentage of data relative to the column associated data is calculated: ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% - summarize_row_groups() %>% +lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> + summarize_row_groups() |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -331,12 +331,12 @@ We can further split the row space by dividing each country by handedness: ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% - summarize_row_groups() %>% - split_rows_by("handed") %>% +lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> + summarize_row_groups() |> + split_rows_by("handed") |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -347,13 +347,13 @@ Next, we further add a count and percentage summary for handedness within each country: ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% - summarize_row_groups() %>% - split_rows_by("handed") %>% - summarize_row_groups() %>% +lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> + summarize_row_groups() |> + split_rows_by("handed") |> + summarize_row_groups() |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) diff --git a/vignettes/sorting_pruning.Rmd b/vignettes/sorting_pruning.Rmd index 412df6763d..59238f5ac2 100644 --- a/vignettes/sorting_pruning.Rmd +++ b/vignettes/sorting_pruning.Rmd @@ -51,13 +51,13 @@ in ways that take into account the table structure. For example: library(rtables) library(dplyr) -raw_lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("SEX") %>% - split_rows_by("RACE") %>% - summarize_row_groups() %>% - split_rows_by("STRATA1") %>% - summarize_row_groups() %>% +raw_lyt <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX") |> + split_rows_by("RACE") |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> + summarize_row_groups() |> analyze("AGE") raw_tbl <- build_table(raw_lyt, DM) @@ -117,10 +117,10 @@ we suggest taking a look at slides 69-76 of this [Slide deck](https://docs.google.com/presentation/d/1ygQE9UaoXY6C_FiQLkiYtXB_OnkVbXvsMIY6_MQPbx0/edit?usp=sharing). In brief, it is important to notice how `[TableTree] RACE` is the root -of the table that is split (with `split_rows_by("RACE") %>%`) into two +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 +`summarize_row_groups() |>`, which creates for every split a "content" table containing 1 row (the 1 in `cont: 1 x 6`), which when rendered takes the place of `LabelRow`. @@ -322,19 +322,19 @@ more_analysis_fnc <- function(x) { ) } -raw_lyt <- basic_table() %>% - split_cols_by("ARM") %>% +raw_lyt <- basic_table() |> + split_cols_by("ARM") |> split_rows_by( "RACE", split_fun = drop_and_remove_levels("WHITE") # dropping WHITE levels - ) %>% - summarize_row_groups() %>% - split_rows_by("STRATA1") %>% - summarize_row_groups() %>% + ) |> + summarize_row_groups() |> + split_rows_by("STRATA1") |> + summarize_row_groups() |> analyze("AGE", afun = more_analysis_fnc) -tbl <- build_table(raw_lyt, DM) %>% - prune_table() %>% +tbl <- build_table(raw_lyt, DM) |> + prune_table() |> print() ``` @@ -432,14 +432,14 @@ within larger splits: ```{r} # Simpler table -tbl <- basic_table() %>% - split_cols_by("ARM") %>% +tbl <- basic_table() |> + split_cols_by("ARM") |> split_cols_by("SEX", split_fun = drop_and_remove_levels(c("U", "UNDIFFERENTIATED")) - ) %>% - analyze("AGE", afun = more_analysis_fnc) %>% - build_table(DM) %>% - prune_table() %>% + ) |> + analyze("AGE", afun = more_analysis_fnc) |> + build_table(DM) |> + prune_table() |> print() sort_at_path(tbl, c("AGE"), scorefun_onecol(colpath = c("ARM", "B: Placebo", "SEX", "F"))) diff --git a/vignettes/split_functions.Rmd b/vignettes/split_functions.Rmd index 613b4a888b..896dfcae88 100644 --- a/vignettes/split_functions.Rmd +++ b/vignettes/split_functions.Rmd @@ -130,10 +130,10 @@ incoherent cells within our table: ```{r examples, message=FALSE} library(rtables) -lyt <- basic_table() %>% - split_cols_by("color") %>% - split_rows_by("vehicle_class") %>% - split_rows_by("vehicle_type") %>% +lyt <- basic_table() |> + split_cols_by("color") |> + split_rows_by("vehicle_class") |> + split_rows_by("vehicle_type") |> analyze("cost") build_table(lyt, vehic_data) @@ -146,10 +146,10 @@ separately within each level of `vehicle_class`, we get a table which only has meaningful combinations: ```{r} -lyt2 <- basic_table() %>% - split_cols_by("color") %>% - split_rows_by("vehicle_class", split_fun = trim_levels_in_group("vehicle_type")) %>% - split_rows_by("vehicle_type") %>% +lyt2 <- basic_table() |> + split_cols_by("color") |> + split_rows_by("vehicle_class", split_fun = trim_levels_in_group("vehicle_type")) |> + split_rows_by("vehicle_type") |> analyze("cost") build_table(lyt2, vehic_data) @@ -185,10 +185,10 @@ map <- tribble( "boat", "cruiseliner" ) -lyt3 <- basic_table() %>% - split_cols_by("color") %>% - split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) %>% - split_rows_by("vehicle_type") %>% +lyt3 <- basic_table() |> + split_cols_by("color") |> + split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) |> + split_rows_by("vehicle_type") |> analyze("cost") build_table(lyt3, vehic_data) @@ -219,10 +219,10 @@ Building further on our arbitrary vehicles table, we can use this to create an "all colors" category: ```{r} -lyt4 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("color", split_fun = add_overall_level("allcolors", label = "All Colors")) %>% - split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) %>% - split_rows_by("vehicle_type") %>% +lyt4 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("color", split_fun = add_overall_level("allcolors", label = "All Colors")) |> + split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) |> + split_rows_by("vehicle_type") |> analyze("cost") build_table(lyt4, vehic_data) @@ -264,10 +264,10 @@ combodf <- tribble( ) -lyt5 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("color", split_fun = add_combo_levels(combodf)) %>% - split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) %>% - split_rows_by("vehicle_type") %>% +lyt5 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("color", split_fun = add_combo_levels(combodf)) |> + split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) |> + split_rows_by("vehicle_type") |> analyze("cost") build_table(lyt5, vehic_data) @@ -392,10 +392,10 @@ silly_splfun1 <- make_split_fun( post = list(sort_them_facets) ) -lyt6 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("color", split_fun = silly_splfun1) %>% - split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) %>% - split_rows_by("vehicle_type") %>% +lyt6 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("color", split_fun = silly_splfun1) |> + split_rows_by("vehicle_class", split_fun = trim_levels_to_map(map)) |> + split_rows_by("vehicle_type") |> analyze("cost") build_table(lyt6, vehic_data) @@ -448,10 +448,10 @@ sense. ```{r} even_sillier_splfun <- make_split_fun(core_split = silly_core_split) -lyt7 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("color") %>% - split_rows_by("vehicle_class", split_fun = even_sillier_splfun) %>% - split_rows_by("vehicle_type") %>% +lyt7 <- basic_table(show_colcounts = TRUE) |> + split_cols_by("color") |> + split_rows_by("vehicle_class", split_fun = even_sillier_splfun) |> + split_rows_by("vehicle_type") |> analyze("cost") build_table(lyt7, vehic_data) diff --git a/vignettes/subsetting_tables.Rmd b/vignettes/subsetting_tables.Rmd index b32d089931..f9ff90f1f9 100644 --- a/vignettes/subsetting_tables.Rmd +++ b/vignettes/subsetting_tables.Rmd @@ -52,12 +52,12 @@ We will use the following table for illustrative purposes: library(rtables) library(dplyr) -lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% +lyt <- basic_table() |> + split_cols_by("ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> analyze(c("AGE", "STRATA1")) -tbl <- build_table(lyt, ex_adsl %>% filter(SEX %in% c("M", "F"))) +tbl <- build_table(lyt, ex_adsl |> filter(SEX %in% c("M", "F"))) tbl ``` @@ -220,14 +220,14 @@ We can see the row and column paths of an existing table via the ```{r} -lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("SEX", split_fun = drop_split_levels) %>% - split_rows_by("RACE", split_fun = drop_split_levels) %>% - summarize_row_groups() %>% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX", split_fun = drop_split_levels) |> + split_rows_by("RACE", split_fun = drop_split_levels) |> + summarize_row_groups() |> analyze(c("AGE", "STRATA1")) -tbl2 <- build_table(lyt2, ex_adsl %>% filter(SEX %in% c("M", "F") & RACE %in% (levels(RACE)[1:3]))) +tbl2 <- build_table(lyt2, ex_adsl |> filter(SEX %in% c("M", "F") & RACE %in% (levels(RACE)[1:3]))) tbl2 ``` diff --git a/vignettes/tabulation_concepts.Rmd b/vignettes/tabulation_concepts.Rmd index af9270bb04..82bfbc0e3c 100644 --- a/vignettes/tabulation_concepts.Rmd +++ b/vignettes/tabulation_concepts.Rmd @@ -63,12 +63,12 @@ df <- tibble( x = rnorm(100), c1 = factor(sample(c("A", "B", "C"), 100, replace = TRUE), levels = c("A", "B", "C")), r1 = factor(sample(c("U", "V", "W"), 100, replace = TRUE), levels = c("U", "V", "W")) -) %>% +) |> mutate( c2 = add_subgroup(c1), r2 = add_subgroup(r1), y = as.numeric(2 * as.numeric(c1) - 3 * as.numeric(r1)) - ) %>% + ) |> select(c1, c2, r1, r2, x, y) df @@ -93,9 +93,9 @@ The data passed to the analysis functions are a subset defined by the respective column and: ```{r} -df_A <- df %>% filter(c1 == "A") -df_B <- df %>% filter(c1 == "B") -df_C <- df %>% filter(c1 == "C") +df_A <- df |> filter(c1 == "A") +df_B <- df |> filter(c1 == "B") +df_C <- df |> filter(c1 == "C") ``` Let's do this on the concrete data with `analyze()`: @@ -105,10 +105,10 @@ foo <- prod bar <- sum zoo <- mean -lyt <- basic_table() %>% - split_cols_by("c1") %>% - analyze("x", function(df) foo(df$x), var_labels = "foo label", format = "xx.xx") %>% - analyze("x", function(df) bar(df$x), var_labels = "bar label", format = "xx.xx") %>% +lyt <- basic_table() |> + split_cols_by("c1") |> + analyze("x", function(df) foo(df$x), var_labels = "foo label", format = "xx.xx") |> + analyze("x", function(df) bar(df$x), var_labels = "bar label", format = "xx.xx") |> analyze("x", function(df) zoo(df$x), var_labels = "zoo label", format = "xx.xx") tbl <- build_table(lyt, df) @@ -139,10 +139,10 @@ in `analyze()` is passed to the function, and if `afun` has an argument `df` then a subset of the dataset is passed to `afun`: ```{r} -lyt2 <- basic_table() %>% - split_cols_by("c1") %>% - analyze("x", foo, var_labels = "foo label", format = "xx.xx") %>% - analyze("x", bar, var_labels = "bar label", format = "xx.xx") %>% +lyt2 <- basic_table() |> + split_cols_by("c1") |> + analyze("x", foo, var_labels = "foo label", format = "xx.xx") |> + analyze("x", bar, var_labels = "bar label", format = "xx.xx") |> analyze("x", zoo, var_labels = "zoo label", format = "xx.xx") tbl2 <- build_table(lyt2, df) @@ -153,14 +153,14 @@ Note that it is also possible that a function returns multiple rows with `in_rows()`: ```{r} -lyt3 <- basic_table() %>% - split_cols_by("c1") %>% +lyt3 <- basic_table() |> + split_cols_by("c1") |> analyze("x", function(x) { in_rows( "row 1" = rcell(mean(x), format = "xx.xx"), "row 2" = rcell(sd(x), format = "xx.xxx") ) - }, var_labels = "foo label") %>% + }, var_labels = "foo label") |> analyze("x", function(x) { in_rows( "more rows 1" = rcell(median(x), format = "xx.x"), @@ -189,15 +189,15 @@ W foo(df_WA) foo(df_WB) foo(df_WC) where `df_*` are subsets of `df` as follows: ```{r} -df_UA <- df %>% filter(r1 == "U", c1 == "A") -df_VA <- df %>% filter(r1 == "V", c1 == "A") -df_WA <- df %>% filter(r1 == "W", c1 == "A") -df_UB <- df %>% filter(r1 == "U", c1 == "B") -df_VB <- df %>% filter(r1 == "V", c1 == "B") -df_WB <- df %>% filter(r1 == "W", c1 == "C") -df_UC <- df %>% filter(r1 == "U", c1 == "C") -df_VC <- df %>% filter(r1 == "V", c1 == "C") -df_WC <- df %>% filter(r1 == "W", c1 == "C") +df_UA <- df |> filter(r1 == "U", c1 == "A") +df_VA <- df |> filter(r1 == "V", c1 == "A") +df_WA <- df |> filter(r1 == "W", c1 == "A") +df_UB <- df |> filter(r1 == "U", c1 == "B") +df_VB <- df |> filter(r1 == "V", c1 == "B") +df_WB <- df |> filter(r1 == "W", c1 == "C") +df_UC <- df |> filter(r1 == "U", c1 == "C") +df_VC <- df |> filter(r1 == "V", c1 == "C") +df_WC <- df |> filter(r1 == "W", c1 == "C") ``` further note that `df_*` are of the same class as `df`, @@ -248,9 +248,9 @@ matrix( In `rtables` this type of tabulation is done with `layouts`: ```{r} -lyt4 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% +lyt4 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> analyze("x", foo) tbl4 <- build_table(lyt4, df) @@ -260,9 +260,9 @@ tbl4 or if we would not want to see the `foo` label we would have to use: ```{r} -lyt5 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% +lyt5 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> summarize_row_groups(cfun = foo, format = "xx") tbl5 <- build_table(lyt5, df) @@ -278,9 +278,9 @@ foo <- function(df, labelstr) { rcell(paste(dim(df), collapse = " x "), format = "xx", label = labelstr) } -lyt6 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% +lyt6 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> summarize_row_groups(cfun = foo) tbl6 <- build_table(lyt6, df) @@ -297,9 +297,9 @@ foo <- function(df, labelstr) { rcell(mean(df$y), label = labelstr, format = "xx.xx") } -lyt7 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% +lyt7 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> summarize_row_groups(cfun = foo) tbl7 <- build_table(lyt7, df) @@ -311,9 +311,9 @@ function body. Let's try some alternatives returning to `analyze()`: ```{r} -lyt8 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% +lyt8 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> analyze("y", afun = mean) tbl8 <- build_table(lyt8, df) @@ -325,9 +325,9 @@ to `mean()`. We could also get the `data.frame` instead of the variable: ```{r} -lyt9 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% +lyt9 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> analyze("y", afun = function(df) mean(df$y)) tbl9 <- build_table(lyt9, df) @@ -337,9 +337,9 @@ tbl9 which is in contrast to: ```{r} -lyt10 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% +lyt10 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> analyze("y", afun = function(x) mean(x)) tbl10 <- build_table(lyt10, df) @@ -374,7 +374,7 @@ where `<>` represents the data that is represented by the cell. So for the cell `U > u1, A` we would have the subset: ```{r} -df %>% +df |> filter(r1 == "U", r2 == "u1", c1 == "A") ``` @@ -382,10 +382,10 @@ and so on. We can get this table as follows: ```{r} -lyt11 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% - split_rows_by("r2") %>% +lyt11 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> + split_rows_by("r2") |> summarize_row_groups(cfun = function(df, labelstr) { rcell(mean(df$x), format = "xx.xx", label = paste("mean x for", labelstr)) }) @@ -405,11 +405,11 @@ s_range <- function(x) { in_rows("range" = rcell(range(x), format = "xx.xx - xx.xx")) } -lyt12 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% - split_rows_by("r2") %>% - analyze("x", s_mean_sd, show_labels = "hidden") %>% +lyt12 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> + split_rows_by("r2") |> + analyze("x", s_mean_sd, show_labels = "hidden") |> analyze("x", s_range, show_labels = "hidden") tbl12 <- build_table(lyt12, df) @@ -501,7 +501,7 @@ W where `s_cfun_2` is the content function and either returns one row via `rcell()` or multiple rows via `in_rows()`. The data represented by `<>` for the content rows is same data as for it's descendant, -i.e. for the `U > u1, A` content row cell it is `df %>% filter(r1 == +i.e. for the `U > u1, A` content row cell it is `df |> filter(r1 == "U", r2 == "u1", c1 == "A")`. Note that content functions `cfun` operate only on data frames and not on vectors/variables so they must take the `df` argument. Further, a `cfun` must also have the @@ -522,12 +522,12 @@ s_cfun_2 <- function(df, labelstr) { rcell(nrow(df), format = "xx", label = paste(labelstr, "(n)")) } -lyt13 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% - split_rows_by("r2") %>% - summarize_row_groups(cfun = s_cfun_2) %>% - analyze("x", s_mean_sd, show_labels = "hidden") %>% +lyt13 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> + split_rows_by("r2") |> + summarize_row_groups(cfun = s_cfun_2) |> + analyze("x", s_mean_sd, show_labels = "hidden") |> analyze("x", s_range, show_labels = "hidden") tbl13 <- build_table(lyt13, df) @@ -538,13 +538,13 @@ In the same manner, if we want content rows for the `r1` split we can do it at as follows: ```{r} -lyt14 <- basic_table() %>% - split_cols_by("c1") %>% - split_rows_by("r1") %>% - summarize_row_groups(cfun = s_cfun_2) %>% - split_rows_by("r2") %>% - summarize_row_groups(cfun = s_cfun_2) %>% - analyze("x", s_mean_sd, show_labels = "hidden") %>% +lyt14 <- basic_table() |> + split_cols_by("c1") |> + split_rows_by("r1") |> + summarize_row_groups(cfun = s_cfun_2) |> + split_rows_by("r2") |> + summarize_row_groups(cfun = s_cfun_2) |> + analyze("x", s_mean_sd, show_labels = "hidden") |> analyze("x", s_range, show_labels = "hidden") tbl14 <- build_table(lyt14, df) diff --git a/vignettes/tabulation_dplyr.Rmd b/vignettes/tabulation_dplyr.Rmd index 75fc8d9387..76abbebdbd 100644 --- a/vignettes/tabulation_dplyr.Rmd +++ b/vignettes/tabulation_dplyr.Rmd @@ -64,17 +64,17 @@ df <- tibble( gender = factor(sample(c("Female", "Male"), n, replace = TRUE), levels = c("Female", "Male")), handed = factor(sample(c("Left", "Right"), n, prob = c(.6, .4), replace = TRUE), levels = c("Left", "Right")), age = rchisq(n, 30) + 10 -) %>% mutate( +) |> mutate( weight = 35 * rnorm(n, sd = .5) + ifelse(gender == "Female", 140, 180) ) -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% - summarize_row_groups() %>% - split_rows_by("handed") %>% - summarize_row_groups() %>% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> + summarize_row_groups() |> + split_rows_by("handed") |> + summarize_row_groups() |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -94,25 +94,25 @@ mean(df$age[df$country == "CAN" & df$arm == "Arm A" & df$gender == "Female" & df or with `dplyr`: ```{r} -df %>% - filter(country == "CAN", arm == "Arm A", gender == "Female", handed == "Left") %>% +df |> + filter(country == "CAN", arm == "Arm A", gender == "Female", handed == "Left") |> summarise(mean_age = mean(age)) ``` Further, `dplyr` gives us other verbs to easily get the average age of left handed Canadians for each group defined by the 4 columns: ```{r} -df %>% - group_by(arm, gender) %>% - filter(country == "CAN", handed == "Left") %>% +df |> + group_by(arm, gender) |> + filter(country == "CAN", handed == "Left") |> summarise(mean_age = mean(age)) ``` We can further get to all the average age cell values with: ```{r} -average_age <- df %>% - group_by(arm, gender, country, handed) %>% +average_age <- df |> + group_by(arm, gender, country, handed) |> summarise(mean_age = mean(age)) average_age @@ -121,11 +121,11 @@ average_age In `rtable` syntax, we need the following code to get to the same content: ```{r} -lyt <- basic_table() %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% - split_rows_by("handed") %>% +lyt <- basic_table() |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> + split_rows_by("handed") |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -143,11 +143,11 @@ We first focus on the count and percentage information for handedness within eac ```{r} -c_h_df <- df %>% - group_by(arm, gender, country, handed) %>% - summarize(mean = mean(age), c_h_count = n()) %>% +c_h_df <- df |> + group_by(arm, gender, country, handed) |> + summarize(mean = mean(age), c_h_count = n()) |> ## we need the sum below to *not* be by country, so that we're dividing by the column counts - ungroup(country) %>% + ungroup(country) |> # now the `handed` grouping has been removed, therefore we can calculate percent now: mutate(n_col = sum(c_h_count), c_h_percent = c_h_count / n_col) c_h_df @@ -156,9 +156,9 @@ c_h_df which has 16 rows (cells) like the `average_age` data frame defined above. Next, we will derive the group information for countries: ```{r} -c_df <- df %>% - group_by(arm, gender, country) %>% - summarize(c_count = n()) %>% +c_df <- df |> + group_by(arm, gender, country) |> + summarize(c_count = n()) |> # now the `handed` grouping has been removed, therefore we can calculate percent now: mutate(n_col = sum(c_count), c_percent = c_count / n_col) c_df @@ -168,7 +168,7 @@ Finally, we `left_join()` the two levels of summary to get a data.frame containi set of values which make up the body of our table (note, however, they are not in the same order): ```{r} -full_dplyr <- left_join(c_h_df, c_df) %>% ungroup() +full_dplyr <- left_join(c_h_df, c_df) |> ungroup() ``` Alternatively, we could calculate only the counts in `c_h_df`, and use @@ -182,13 +182,13 @@ self-contained set of computations. The `rtables` call in contrast is: ```{r} -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("arm") %>% - split_cols_by("gender") %>% - split_rows_by("country") %>% - summarize_row_groups() %>% - split_rows_by("handed") %>% - summarize_row_groups() %>% +lyt <- basic_table(show_colcounts = TRUE) |> + split_cols_by("arm") |> + split_cols_by("gender") |> + split_rows_by("country") |> + summarize_row_groups() |> + split_rows_by("handed") |> + summarize_row_groups() |> analyze("age", afun = mean, format = "xx.x") tbl <- build_table(lyt, df) @@ -205,8 +205,8 @@ frm_rtables_h <- cell_values( )[[1]] frm_rtables_h -frm_dplyr_h <- full_dplyr %>% - filter(country == "CAN" & handed == "Right" & arm == "Arm B" & gender == "Female") %>% +frm_dplyr_h <- full_dplyr |> + filter(country == "CAN" & handed == "Right" & arm == "Arm B" & gender == "Female") |> select(c_h_count, c_h_percent) frm_dplyr_h @@ -220,8 +220,8 @@ frm_rtables_c <- cell_values( frm_rtables_c -frm_dplyr_c <- full_dplyr %>% - filter(country == "CAN" & arm == "Arm A" & gender == "Male") %>% +frm_dplyr_c <- full_dplyr |> + filter(country == "CAN" & arm == "Arm A" & gender == "Male") |> select(c_count, c_percent) frm_dplyr_c diff --git a/vignettes/title_footer.Rmd b/vignettes/title_footer.Rmd index 83b5cef20a..73a9b4b7b1 100644 --- a/vignettes/title_footer.Rmd +++ b/vignettes/title_footer.Rmd @@ -64,10 +64,10 @@ lyt <- basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", split_fun = drop_split_levels) %>% - split_rows_by("STRATA1") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX", split_fun = drop_split_levels) |> + split_rows_by("STRATA1") |> analyze("AGE", mean, format = "xx.x") tbl <- build_table(lyt, DM) @@ -95,10 +95,10 @@ lyt2 <- basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", page_by = TRUE, page_prefix = "Patient Subset - Gender", split_fun = drop_split_levels) %>% - split_rows_by("STRATA1") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX", page_by = TRUE, page_prefix = "Patient Subset - Gender", split_fun = drop_split_levels) |> + split_rows_by("STRATA1") |> analyze("AGE", mean, format = "xx.x") tbl2 <- build_table(lyt2, DM) @@ -116,10 +116,10 @@ lyt3 <- basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", page_by = TRUE, page_prefix = "Patient Subset - Gender", split_fun = drop_split_levels) %>% - split_rows_by("STRATA1", page_by = TRUE, page_prefix = "Stratification - Strata") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX", page_by = TRUE, page_prefix = "Patient Subset - Gender", split_fun = drop_split_levels) |> + split_rows_by("STRATA1", page_by = TRUE, page_prefix = "Stratification - Strata") |> analyze("AGE", mean, format = "xx.x") tbl3 <- build_table(lyt3, DM) @@ -162,10 +162,10 @@ lyt <- basic_table( subtitles = c("subtitle YYYYYYYYYY", "subtitle2 ZZZZZZZZZ"), main_footer = "Analysis was done using cool methods that are correct", prov_footer = "file: /path/to/stuff/that/lives/there HASH:1ac41b242a" -) %>% - split_cols_by("ARM") %>% - split_rows_by("SEX", page_by = TRUE, page_prefix = "Patient Subset - Gender", split_fun = drop_split_levels) %>% - split_rows_by("STRATA1") %>% +) |> + split_cols_by("ARM") |> + split_rows_by("SEX", page_by = TRUE, page_prefix = "Patient Subset - Gender", split_fun = drop_split_levels) |> + split_rows_by("STRATA1") |> analyze("AGE", afun, format = "xx.x") tbl <- build_table(lyt, DM) @@ -199,16 +199,16 @@ those cannot be controlled within an analysis or content function. paste(toupper(substring(s, 1, 1)), substring(s, 2), sep = "", collapse = " ") } -adsl2 <- ex_adsl %>% - filter(SEX %in% c("M", "F") & RACE %in% (levels(RACE)[1:3])) %>% +adsl2 <- ex_adsl |> + filter(SEX %in% c("M", "F") & RACE %in% (levels(RACE)[1:3])) |> ## we trim the level names here solely due to space considerations mutate(ethnicity = .simpleCap(gsub("(.*)OR.*", "\\1", RACE)), RACE = factor(RACE)) -lyt2 <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("SEX", split_fun = drop_split_levels) %>% - split_rows_by("RACE", labels_var = "ethnicity", split_fun = drop_split_levels) %>% - summarize_row_groups() %>% +lyt2 <- basic_table() |> + split_cols_by("ARM") |> + split_cols_by("SEX", split_fun = drop_split_levels) |> + split_rows_by("RACE", labels_var = "ethnicity", split_fun = drop_split_levels) |> + summarize_row_groups() |> analyze(c("AGE", "STRATA1")) tbl2 <- build_table(lyt2, adsl2)