Skip to content

Commit

Permalink
Sanitize tables (#102)
Browse files Browse the repository at this point in the history
Part of insightsengineering/tern#992

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
edelarua and github-actions[bot] committed Aug 23, 2023
1 parent d9380ba commit 9cd8f4b
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 68 deletions.
17 changes: 12 additions & 5 deletions book/tables/adverse-events/aet02_smq.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ result
## Table with Customized Queries

```{r variant2, test = list(result_v2 = "result")}
criteria_fun <- function(tr) !is(tr, "ContentRow") && all_zero_or_na(tr)
criteria_fun <- function(tr) {
!is(tr, "ContentRow") && all_zero_or_na(tr) && !grepl("Total number of", obj_label(tr))
}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARMCD") %>%
Expand All @@ -135,27 +137,32 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
label_pos = "topleft",
split_label = "Standardized MedDRA Query"
) %>%
summarize_num_patients(
analyze_num_patients(
var = "USUBJID",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one adverse event",
nonunique = "Total number of events"
)
),
show_labels = "hidden"
) %>%
count_occurrences(
vars = "AEDECOD",
.indent_mods = -1L,
drop = FALSE
) %>%
append_varlabels(adae, "AEDECOD", indent = 1L)
score_ae_pts <- function(tt) {
count_vals <- cell_values(tree_children(tt)[["USUBJID"]])[[1]]
sum(matrix(unlist(count_vals), nrow = length(count_vals), byrow = TRUE)[, 1])
}
result <- build_table(
lyt,
df = adae_smq_all,
alt_counts_df = adsl
) %>%
sort_at_path(path = c("SMQ"), scorefun = cont_n_allcols) %>%
sort_at_path(path = c("SMQ"), scorefun = score_ae_pts) %>%
sort_at_path(path = c("SMQ", "*", "AEDECOD"), scorefun = score_occurrences, na.pos = "last") %>%
trim_rows(criteria = criteria_fun)
Expand Down
4 changes: 2 additions & 2 deletions book/tables/adverse-events/aet05_all.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
estimate_incidence_rate(
vars = "AVAL",
n_events = "n_events",
control = control_incidence_rate(time_unit_output = 100)
control = control_incidence_rate(num_pt_year = 100)
)
result <- build_table(lyt, anl, alt_counts_df = adsl)
Expand All @@ -62,7 +62,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
estimate_incidence_rate(
vars = "AVAL",
n_events = "n_events",
control = control_incidence_rate(conf_type = "exact", time_unit_output = 100)
control = control_incidence_rate(conf_type = "exact", num_pt_year = 100)
)
result <- build_table(lyt, anl, alt_counts_df = adsl)
Expand Down
16 changes: 12 additions & 4 deletions book/tables/adverse-events/aet06_smq.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ result
## Adverse Events by Sex, by SMQ and <br/> Preferred Term (with Customized Queries)

```{r variant2, test = list(result_v2 = "result")}
criteria_fun <- function(tr) !is(tr, "ContentRow") && all_zero_or_na(tr)
criteria_fun <- function(tr) {
!is(tr, "ContentRow") && all_zero_or_na(tr) && !grepl("Total number of", obj_label(tr))
}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARMCD") %>%
Expand All @@ -160,23 +162,29 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
label_pos = "topleft",
split_label = "Standardized MedDRA Query"
) %>%
summarize_num_patients(
analyze_num_patients(
var = "USUBJID",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one adverse event",
nonunique = "Total number of events"
)
),
show_labels = "hidden"
) %>%
count_occurrences(vars = "AEDECOD", drop = FALSE) %>%
append_varlabels(adae_smq_all, "AEDECOD", indent = 1L)
score_ae_pts <- function(tt) {
count_vals <- cell_values(tree_children(tt)[["USUBJID"]])[[1]]
sum(matrix(unlist(count_vals), nrow = length(count_vals), byrow = TRUE)[, 1])
}
result <- build_table(
lyt = lyt,
df = adae_smq_all,
alt_counts_df = adsl
) %>%
sort_at_path(path = c("SMQ"), scorefun = cont_n_allcols) %>%
sort_at_path(path = c("SMQ"), scorefun = score_ae_pts) %>%
sort_at_path(path = c("SMQ", "*", "AEDECOD"), scorefun = score_occurrences, na.pos = "last") %>%
trim_rows(criteria = criteria_fun)
Expand Down
17 changes: 12 additions & 5 deletions book/tables/adverse-events/aet09_smq.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ result
## Table with Customized Queries

```{r variant2, test = list(result_v2 = "result")}
criteria_fun <- function(tr) !is(tr, "ContentRow") && all_zero_or_na(tr)
criteria_fun <- function(tr) {
!is(tr, "ContentRow") && all_zero_or_na(tr) && !grepl("Total number of", obj_label(tr))
}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARMCD") %>%
Expand All @@ -139,27 +141,32 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
label_pos = "topleft",
split_label = "Standardized MedDRA Query"
) %>%
summarize_num_patients(
analyze_num_patients(
var = "USUBJID",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one adverse event",
nonunique = "Total number of events"
)
),
show_labels = "hidden"
) %>%
count_occurrences(
vars = "AEDECOD",
.indent_mods = -1L,
drop = FALSE
) %>%
append_varlabels(adae, "AEDECOD", indent = 1L)
score_ae_pts <- function(tt) {
count_vals <- cell_values(tree_children(tt)[["USUBJID"]])[[1]]
sum(matrix(unlist(count_vals), nrow = length(count_vals), byrow = TRUE)[, 1])
}
result <- build_table(
lyt,
df = adae_smq_all,
alt_counts_df = adsl
) %>%
sort_at_path(path = c("SMQ"), scorefun = cont_n_allcols) %>%
sort_at_path(path = c("SMQ"), scorefun = score_ae_pts) %>%
sort_at_path(path = c("SMQ", "*", "AEDECOD"), scorefun = score_occurrences, na.pos = "last") %>%
trim_rows(criteria = criteria_fun)
Expand Down
25 changes: 12 additions & 13 deletions book/tables/efficacy/dort01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 2L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand All @@ -89,7 +88,8 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
time_point = 12
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table(prune_func = prune_zeros_only)
result
```
Expand Down Expand Up @@ -120,8 +120,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 2L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand All @@ -144,7 +143,8 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
table_names = "cox_pair"
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table(prune_func = prune_zeros_only)
result
```
Expand Down Expand Up @@ -175,8 +175,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 2L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand All @@ -199,7 +198,8 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
control = control_surv_timepoint(conf_level = 0.975)
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table(prune_func = prune_zeros_only)
result
```
Expand Down Expand Up @@ -230,8 +230,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 2L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand All @@ -252,7 +251,8 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
time_point = 6
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table(prune_func = prune_zeros_only)
result
```
Expand Down Expand Up @@ -323,5 +323,4 @@ shinyApp(app$ui, app$server)
```

{{< include ../../repro.qmd >}}

:::
3 changes: 1 addition & 2 deletions book/tables/efficacy/mmrmt01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ adsl <- df_explicit_na(adsl)
adqs <- df_explicit_na(adqs)
adqs_f <- adqs %>%
dplyr::filter(PARAMCD == "FKSI-FWB" & !AVISIT %in% c("BASELINE")) %>%
dplyr::filter(PARAMCD == "FKSI-FWB" & !AVISIT %in% c("BASELINE", "SCREENING")) %>%
droplevels() %>%
dplyr::mutate(ARMCD = factor(ARMCD, levels = c("ARM B", "ARM A", "ARM C"))) %>%
dplyr::mutate(
Expand Down Expand Up @@ -275,5 +275,4 @@ shinyApp(app$ui, app$server)
```

{{< include ../../repro.qmd >}}

:::
36 changes: 20 additions & 16 deletions book/tables/efficacy/ttet01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 1L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand Down Expand Up @@ -92,7 +91,9 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
control = control_surv_timepoint()
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```

Expand Down Expand Up @@ -156,8 +157,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 1L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand Down Expand Up @@ -201,7 +201,9 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
table_names_suffix = "_975_pct"
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```

Expand All @@ -223,8 +225,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 1L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand Down Expand Up @@ -259,7 +260,9 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
time_point = 12
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```

Expand All @@ -281,8 +284,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 1L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand Down Expand Up @@ -311,7 +313,9 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
method = "both"
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```

Expand All @@ -333,8 +337,7 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
child_labels = "hidden",
indent_mod = 1L,
) %>%
split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>%
summarize_row_groups(format = "xx") %>%
analyze("EVNTDESC") %>%
summarize_vars(
vars = "is_not_event",
.stats = "count_fraction",
Expand Down Expand Up @@ -381,7 +384,9 @@ lyt <- basic_table(show_colcounts = TRUE) %>%
method = "both"
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```

Expand Down Expand Up @@ -450,5 +455,4 @@ shinyApp(app$ui, app$server)
```

{{< include ../../repro.qmd >}}

:::
Loading

0 comments on commit 9cd8f4b

Please sign in to comment.