Skip to content

Commit

Permalink
move occurrence layout to rtable utils.R
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkliming committed Aug 2, 2023
1 parent e7b16e0 commit f4befd1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 59 deletions.
1 change: 0 additions & 1 deletion R/aet10.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ aet10_post <- function(tlg, atleast = 0.05, ...) {
#' run(aet10, syn_data)
aet10 <- chevron_t(
main = aet10_main,
lyt = aet10_lyt,
preprocess = aet10_pre,
postprocess = aet10_post
)
54 changes: 0 additions & 54 deletions R/cmt01a.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,59 +81,6 @@ cmt01a_main <- function(adam_db,
tbl
}

#' Occurrence Layout
#'
#' @inheritParams gen_args
#' @inheritParams cmt01a_main
#' @param lbl_medname_var (`string`) label for the variable defining the medication name.
#' @keywords internal
#'
occurrence_lyt <- function(arm_var,
lbl_overall,
row_split_var,
lbl_row_split,
medname_var,
lbl_medname_var,
summary_labels,
count_by) {
split_indent <- vapply(c("TOTAL", row_split_var), function(x) {
if (length(summary_labels[[x]]) > 0L) -1L else 0L
}, FUN.VALUE = 0L)
split_indent[1L] <- 0L
lyt <- basic_table() %>%
split_cols_by(var = arm_var) %>%
add_colcounts() %>%
ifneeded_add_overall_col(lbl_overall)
if (length(summary_labels$TOTAL) > 0) {
lyt <- lyt %>%
analyze_num_patients(
vars = "USUBJID",
count_by = count_by,
.stats = names(summary_labels$TOTAL),
show_labels = "hidden",
.labels = render_safe(summary_labels$TOTAL)
)
}
for (k in seq_len(length(row_split_var))) {
lyt <- split_and_summ_num_patients(
lyt = lyt,
count_by = count_by,
var = row_split_var[k],
label = lbl_row_split[k],
split_indent = split_indent[k],
stats = names(summary_labels[[row_split_var[k]]]),
summarize_labels = render_safe(summary_labels[[row_split_var[k]]])
)
}
lyt %>%
count_occurrences(
vars = medname_var,
drop = length(row_split_var) > 0,
.indent_mods = unname(tail(split_indent, 1L))
) %>%
append_topleft(paste0(stringr::str_dup(" ", 2 * length(row_split_var)), lbl_medname_var))
}

#' @describeIn cmt01a Preprocessing
#'
#' @inheritParams cmt01a_main
Expand Down Expand Up @@ -199,7 +146,6 @@ cmt01a_post <- function(
#' run(cmt01a, proc_data)
cmt01a <- chevron_t(
main = cmt01a_main,
lyt = occurrence_lyt,
preprocess = cmt01a_pre,
postprocess = cmt01a_post
)
1 change: 0 additions & 1 deletion R/cmt02_pt.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ cmt02_pt_post <- modify_default_args(cmt01a_post, row_split_var = NULL)
#' run(cmt02_pt, syn_data)
cmt02_pt <- chevron_t(
main = cmt02_pt_main,
lyt = cmt02_pt_lyt,
preprocess = cmt02_pt_pre,
postprocess = cmt02_pt_post
)
1 change: 0 additions & 1 deletion R/pdt01.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ pdt01_post <- function(tlg, prune_0 = TRUE, dvcode_var = "DVDECOD", dvterm_var =
#' run(pdt01, proc_data)
pdt01 <- chevron_t(
main = pdt01_main,
lyt = pdt01_lyt,
preprocess = pdt01_pre,
postprocess = pdt01_post
)
1 change: 0 additions & 1 deletion R/pdt02.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ pdt02_post <- function(tlg, prune_0 = TRUE, dvreas_var = "DVREAS", dvterm_var =
#' run(pdt02, syn_data)
pdt02 <- chevron_t(
main = pdt02_main,
lyt = pdt02_lyt,
preprocess = pdt02_pre,
postprocess = pdt02_post
)
54 changes: 54 additions & 0 deletions R/rtables_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,57 @@ infer_mapping <- function(map_df, df) {
res
}
}


#' Occurrence Layout
#'
#' @inheritParams gen_args
#' @inheritParams cmt01a_main
#' @param lbl_medname_var (`string`) label for the variable defining the medication name.
#' @keywords internal
#'
occurrence_lyt <- function(arm_var,
lbl_overall,
row_split_var,
lbl_row_split,
medname_var,
lbl_medname_var,
summary_labels,
count_by) {
split_indent <- vapply(c("TOTAL", row_split_var), function(x) {
if (length(summary_labels[[x]]) > 0L) -1L else 0L
}, FUN.VALUE = 0L)
split_indent[1L] <- 0L
lyt <- basic_table() %>%
split_cols_by(var = arm_var) %>%
add_colcounts() %>%
ifneeded_add_overall_col(lbl_overall)
if (length(summary_labels$TOTAL) > 0) {
lyt <- lyt %>%
analyze_num_patients(
vars = "USUBJID",
count_by = count_by,
.stats = names(summary_labels$TOTAL),
show_labels = "hidden",
.labels = render_safe(summary_labels$TOTAL)
)
}
for (k in seq_len(length(row_split_var))) {
lyt <- split_and_summ_num_patients(
lyt = lyt,
count_by = count_by,
var = row_split_var[k],
label = lbl_row_split[k],
split_indent = split_indent[k],
stats = names(summary_labels[[row_split_var[k]]]),
summarize_labels = render_safe(summary_labels[[row_split_var[k]]])
)
}
lyt %>%
count_occurrences(
vars = medname_var,
drop = length(row_split_var) > 0,
.indent_mods = unname(tail(split_indent, 1L))
) %>%
append_topleft(paste0(stringr::str_dup(" ", 2 * length(row_split_var)), lbl_medname_var))
}
2 changes: 1 addition & 1 deletion man/occurrence_lyt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f4befd1

Please sign in to comment.