# NOT RUN {
s_summary <- function(x) {
if (is.numeric(x)) {
in_rows(
"n" = rcell(sum(!is.na(x)), format = "xx"),
"Mean (sd)" = rcell(c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE)),
format = "xx.xx (xx.xx)"),
"IQR" = rcell(IQR(x, na.rm = TRUE), format = "xx.xx"),
"min - max" = rcell(range(x, na.rm = TRUE), format = "xx.xx - xx.xx")
)
} else if (is.factor(x)) {
vs <- as.list(table(x))
do.call(in_rows, lapply(vs, rcell, format = "xx"))
} else (
stop("type not supported")
)
}
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)
tbl
nrow(tbl)
row_paths_summary(tbl)
tbls <- paginate_table(tbl)
w_tbls <- propose_column_widths(tbl) # so that we have the same column widths
tmp <- lapply(tbls, print, widths = w_tbls)
tmp <- lapply(tbls, function(tbli) {
cat(toString(tbli, widths = w_tbls))
cat("\n\n")
cat("~~~~ PAGE BREAK ~~~~")
cat("\n\n")
})
# }
Run the code above in your browser using DataLab