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

Refactor tabulate_rsp_subgroups to pass sanitation checks #1056

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# tern 0.9.0.9000
### Enhancements
* Refactored `tabulate_rsp_subgroups` to pass sanitation checks by preventing creation of degenerate subtables.

# tern 0.9.0
### New Features
Expand Down
40 changes: 22 additions & 18 deletions R/response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,23 @@ tabulate_rsp_subgroups <- function(lyt,
# Columns from table_prop are optional.
if (length(colvars_prop$vars) > 0) {
lyt_prop <- split_cols_by(lyt = lyt, var = "arm")
lyt_prop <- split_cols_by_multivar(
lyt = lyt_prop,
vars = colvars_prop$vars,
varlabels = colvars_prop$labels
)

# "All Patients" row
lyt_prop <- split_rows_by(
lyt = lyt_prop,
var = "row_type",
split_fun = keep_split_levels("content"),
nested = FALSE
)
lyt_prop <- summarize_row_groups(
lyt = lyt_prop,
var = "var_label",
cfun = afun_lst[names(colvars_prop$labels)]
nested = FALSE,
child_labels = "hidden"
)
lyt_prop <- split_cols_by_multivar(
lyt_prop <- analyze_colvars(
lyt = lyt_prop,
vars = colvars_prop$vars,
varlabels = colvars_prop$labels
afun = afun_lst[names(colvars_prop$labels)]
)

if ("analysis" %in% df$prop$row_type) {
Expand All @@ -268,21 +270,23 @@ tabulate_rsp_subgroups <- function(lyt,

# Columns "n_tot", "or", "ci" in table_or are required.
lyt_or <- split_cols_by(lyt = lyt, var = "arm")
lyt_or <- split_rows_by(
lyt = lyt_or,
var = "row_type",
split_fun = keep_split_levels("content"),
nested = FALSE
)
lyt_or <- split_cols_by_multivar(
lyt = lyt_or,
vars = colvars_or$vars,
varlabels = colvars_or$labels
)
lyt_or <- summarize_row_groups(

# "All Patients" row
lyt_or <- split_rows_by(
lyt = lyt_or,
var = "row_type",
split_fun = keep_split_levels("content"),
nested = FALSE,
child_labels = "hidden"
)
lyt_or <- analyze_colvars(
lyt = lyt_or,
var = "var_label",
cfun = afun_lst[names(colvars_or$labels)]
afun = afun_lst[names(colvars_or$labels)]
) %>%
append_topleft("Baseline Risk Factors")

Expand Down