Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support displaying column counts at higher levels in column structure #856

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export("col_footnotes<-")
export("col_info<-")
export("col_total<-")
export("colcount_format<-")
export("colcount_na_str<-")
export("colcount_visible<-")
export("content_table<-")
export("facet_colcount<-")
export("fnotes_at_path<-")
export("header_section_div<-")
export("horizontal_sep<-")
Expand Down Expand Up @@ -74,6 +77,8 @@ export(col_paths)
export(col_paths_summary)
export(col_total)
export(colcount_format)
export(colcount_na_str)
export(colcount_visible)
export(collect_leaves)
export(coltree)
export(compare_rtables)
Expand All @@ -91,6 +96,7 @@ export(export_as_docx)
export(export_as_pdf)
export(export_as_tsv)
export(export_as_txt)
export(facet_colcount)
export(find_degen_struct)
export(format_rcell)
export(get_formatted_cells)
Expand Down Expand Up @@ -138,6 +144,7 @@ export(remove_split_levels)
export(reorder_split_levels)
export(result_df_specs)
export(rheader)
export(rm_all_colcounts)
export(row_cells)
export(row_footnotes)
export(row_paths)
Expand Down Expand Up @@ -208,7 +215,10 @@ exportMethods("col_footnotes<-")
exportMethods("col_info<-")
exportMethods("col_total<-")
exportMethods("colcount_format<-")
exportMethods("colcount_na_str<-")
exportMethods("colcount_visible<-")
exportMethods("content_table<-")
exportMethods("facet_colcount<-")
exportMethods("fnotes_at_path<-")
exportMethods("horizontal_sep<-")
exportMethods("main_footer<-")
Expand Down Expand Up @@ -239,10 +249,13 @@ exportMethods(col_footnotes)
exportMethods(col_info)
exportMethods(col_total)
exportMethods(colcount_format)
exportMethods(colcount_na_str)
exportMethods(colcount_visible)
exportMethods(collect_leaves)
exportMethods(coltree)
exportMethods(content_table)
exportMethods(dim)
exportMethods(facet_colcount)
exportMethods(head)
exportMethods(horizontal_sep)
exportMethods(length)
Expand All @@ -266,6 +279,7 @@ exportMethods(rbind2)
exportMethods(ref_index)
exportMethods(ref_msg)
exportMethods(ref_symbol)
exportMethods(rm_all_colcounts)
exportMethods(row.names)
exportMethods(row_cells)
exportMethods(row_footnotes)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Added `top_level_section_div` for `basic_table` to set section dividers for top level rows.
* Added `keep_label_rows` to `as_result_df` to have these lines visible.
* `sort_at_path` now gives informative error messages when the given path does not exist.
* Added Support for displaying column counts for higher-level facets in the column structure, PR from @gmbecker

### Bug Fixes
* Fixed `rlistings` decoration (e.g. titles and footers) expansion when there are new lines. Moved relevant handling from `rtables`' `matrix_form` function to `formatters`' dedicated `mform_handle_newlines` function.
Expand Down
100 changes: 72 additions & 28 deletions R/00tabletrees.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ setClass("Split",
content_indent_modifier = "integer",
content_extra_args = "list",
page_title_prefix = "character",
child_section_div = "character"
child_section_div = "character",
child_show_colcounts = "logical",
child_colcount_format = "character"
)
)

Expand Down Expand Up @@ -185,7 +187,9 @@ VarLevelSplit <- function(var,
cvar = "",
cextra_args = list(),
page_prefix = NA_character_,
section_div = NA_character_) {
section_div = NA_character_,
show_colcounts = FALSE,
colcount_format = "(N=xx)") {
child_labels <- match.arg(child_labels)
if (is.null(labels_var)) {
labels_var <- var
Expand All @@ -211,7 +215,9 @@ VarLevelSplit <- function(var,
split_label_position = label_pos,
content_extra_args = cextra_args,
page_title_prefix = page_prefix,
child_section_div = section_div
child_section_div = section_div,
child_show_colcounts = show_colcounts,
child_colcount_format = colcount_format
)
}

Expand All @@ -229,6 +235,8 @@ AllSplit <- function(split_label = "",
cindent_mod = 0L,
cvar = "",
cextra_args = list(),
show_colcounts = FALSE,
colcount_format = "(N=xx)",
...) {
if (is.null(split_name)) {
if (nzchar(split_label)) {
Expand All @@ -254,7 +262,9 @@ AllSplit <- function(split_label = "",
split_label_position = "hidden",
content_extra_args = cextra_args,
page_title_prefix = NA_character_,
child_section_div = NA_character_
child_section_div = NA_character_,
child_show_colcounts = show_colcounts,
child_colcount_format = colcount_format
)
}

Expand All @@ -277,7 +287,9 @@ RootSplit <- function(split_label = "", cfun = NULL, cformat = NULL, cna_str = N
content_var = cvar,
split_label_position = "hidden",
content_extra_args = cextra_args,
child_section_div = NA_character_
child_section_div = NA_character_,
child_show_colcounts = FALSE,
child_colcount_format = "(N=xx)"
)
}

Expand Down Expand Up @@ -321,7 +333,9 @@ ManualSplit <- function(levels, label, name = "manual",
split_na_str = NA_character_,
split_label_position = label_pos,
page_title_prefix = page_prefix,
child_section_div = section_div
child_section_div = section_div,
child_show_colcounts = FALSE,
child_colcount_format = "(N=xx)"
)
}

Expand Down Expand Up @@ -394,7 +408,9 @@ MultiVarSplit <- function(vars,
label_pos = "visible",
split_fun = NULL,
page_prefix = NA_character_,
section_div = NA_character_) {
section_div = NA_character_,
show_colcounts = FALSE,
colcount_format = "(N=xx)") {
check_ok_label(split_label)
## no topleft allowed
label_pos <- match.arg(label_pos, label_pos_values[-3])
Expand Down Expand Up @@ -427,7 +443,9 @@ MultiVarSplit <- function(vars,
content_extra_args = cextra_args,
split_fun = split_fun,
page_title_prefix = page_prefix,
child_section_div = section_div
child_section_div = section_div,
child_show_colcounts = show_colcounts,
child_colcount_format = colcount_format
)
}

Expand Down Expand Up @@ -480,7 +498,9 @@ make_static_cut_split <- function(var,
label_pos = "visible",
cumulative = FALSE,
page_prefix = NA_character_,
section_div = NA_character_) {
section_div = NA_character_,
show_colcounts = FALSE,
colcount_format = "(N=xx)") {
cls <- if (cumulative) "CumulativeCutSplit" else "VarStaticCutSplit"
check_ok_label(split_label)

Expand Down Expand Up @@ -517,7 +537,9 @@ make_static_cut_split <- function(var,
split_label_position = label_pos,
content_extra_args = cextra_args,
page_title_prefix = page_prefix,
child_section_div = section_div
child_section_div = section_div,
child_show_colcounts = show_colcounts,
child_colcount_format = colcount_format
)
}

Expand Down Expand Up @@ -564,7 +586,9 @@ VarDynCutSplit <- function(var,
cextra_args = list(),
label_pos = "visible",
page_prefix = NA_character_,
section_div = NA_character_) {
section_div = NA_character_,
show_colcounts = FALSE,
colcount_format = "(N=xx)") {
check_ok_label(split_label)
label_pos <- match.arg(label_pos, label_pos_values)
child_labels <- match.arg(child_labels)
Expand All @@ -588,7 +612,9 @@ VarDynCutSplit <- function(var,
split_label_position = label_pos,
content_extra_args = cextra_args,
page_title_prefix = page_prefix,
child_section_div = section_div
child_section_div = section_div,
child_show_colcounts = show_colcounts,
child_colcount_format = colcount_format
)
}

Expand Down Expand Up @@ -664,7 +690,9 @@ AnalyzeVarSplit <- function(var,
var_label_position = label_pos,
content_var = cvar,
page_title_prefix = NA_character_,
child_section_div = section_div
child_section_div = section_div,
child_show_colcounts = FALSE,
child_colcount_format = NA_character_
) ## no content_extra_args
}

Expand Down Expand Up @@ -708,7 +736,9 @@ AnalyzeColVarSplit <- function(afun,
var_label_position = label_pos,
content_var = cvar,
page_title_prefix = NA_character_,
child_section_div = section_div
child_section_div = section_div,
child_show_colcounts = FALSE,
child_colcount_format = NA_character_
) ## no content_extra_args
}

Expand Down Expand Up @@ -902,7 +932,9 @@ VarLevWBaselineSplit <- function(var,
split_na_str = NA_character_,
valorder = NULL,
split_name = var,
extra_args = list()) {
extra_args = list(),
show_colcounts = FALSE,
colcount_format = "(N=xx)") {
check_ok_label(split_label)
new("VarLevWBaselineSplit",
payload = var,
Expand All @@ -928,7 +960,9 @@ VarLevWBaselineSplit <- function(var,
content_var = cvar,
## so long as this is columnspace only
page_title_prefix = NA_character_,
child_section_div = NA_character_
child_section_div = NA_character_,
child_show_colcounts = show_colcounts,
child_colcount_format = colcount_format
)
}

Expand Down Expand Up @@ -1057,11 +1091,15 @@ setClass("LayoutAxisTree",
}
)

## this is only used for columns!!!!
setClass("LayoutAxisLeaf",
contains = "VLayoutLeaf", ## "VNodeInfo",
representation(
func = "function",
col_footnotes = "list"
display_columncounts = "logical",
columncount_format = "character",
col_footnotes = "list",
column_count = "integer"
)
)

Expand All @@ -1070,7 +1108,8 @@ setClass("LayoutColTree",
representation(
display_columncounts = "logical",
columncount_format = "character",
col_footnotes = "list"
col_footnotes = "list",
column_count = "integer"
)
)

Expand All @@ -1082,9 +1121,10 @@ LayoutColTree <- function(lev = 0L,
spl = EmptyAllSplit,
tpos = TreePos(),
summary_function = NULL,
disp_colcounts = FALSE,
disp_ccounts = FALSE,
colcount_format = "(N=xx)",
footnotes = list()) { ## ,
footnotes = list(),
colcount) { ## ,
## sub = expression(TRUE),
## svar = NA_character_,
## slab = NA_character_) {
Expand All @@ -1105,23 +1145,27 @@ LayoutColTree <- function(lev = 0L,
## subset = sub,
## splitvar = svar,
label = label,
display_columncounts = disp_colcounts,
display_columncounts = disp_ccounts,
columncount_format = colcount_format,
col_footnotes = footnotes
col_footnotes = footnotes,
column_count = colcount
)
}

LayoutColLeaf <- function(lev = 0L,
name = label,
label = "",
tpos = TreePos()) {
tpos = TreePos(),
colcount,
disp_ccounts = FALSE,
colcount_format = "(N=xx)") {
check_ok_label(label)
new("LayoutColLeaf",
level = lev, name = .chkname(name), label = label,
pos_in_tree = tpos ## ,
## subset = sub#,
## N_count = n,
## splitvar = svar
pos_in_tree = tpos,
column_count = colcount,
display_columncounts = disp_ccounts,
columncount_format = colcount_format
)
}

Expand Down Expand Up @@ -1168,7 +1212,7 @@ setClass(
#'
#' @export
#' @rdname cinfo
InstantiatedColumnInfo <- function(treelyt = LayoutColTree(),
InstantiatedColumnInfo <- function(treelyt = LayoutColTree(colcount = total_cnt),
csubs = list(expression(TRUE)),
extras = list(list()),
cnts = NA_integer_,
Expand Down
8 changes: 7 additions & 1 deletion R/argument_conventions.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ gen_args <- function(df, alt_counts_df, spl, pos, tt, tr, verbose, colwidths, ob
#' uniqueness.
#' @param vars (`character`)\cr vector of variable names.
#' @param var_labels (`character`)\cr vector of labels for one or more variables.
#' @param show_colcounts (`logical(1)`)\cr Should column counts be displayed at the level
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
#' facets created by this split. Defaults to `FALSE`.
#' @param colcount_format (`character(1)`)\cr If `show_colcounts` is `TRUE`, the
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
#' format which should be used to display column counts for facets generated by
#' this split. Defaults to `"(N=xx)"`.
#'
#' @inherit gen_args return
#'
Expand All @@ -136,7 +141,8 @@ lyt_args <- function(lyt, var, vars, label, labels_var, varlabels, varnames, spl
indent_mod, show_labels, label_pos, # visible_label,
var_labels, cvar,
table_names, topleft, align, page_by, page_prefix,
format_na_str, section_div, na_str) {
format_na_str, section_div, na_str, show_colcounts,
colcount_format) {
NULL
}

Expand Down
Loading
Loading