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

Fix reorder columns #256

Merged
merged 20 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
39 changes: 27 additions & 12 deletions book/tables/ADA/adat01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,32 @@ library(tibble)
adsl <- random.cdisc.data::cadsl
adab <- random.cdisc.data::cadab

combodf <- tribble(
~valname, ~label, ~levelcombo, ~exargs,
"all_X", "All Drug X", c("A: Drug X", "C: Combination"), list(),
"all_pt", "All Patients", c("A: Drug X", "B: Placebo", "C: Combination"), list()
# Order needed for the columns is c(1, 3, 4, 2, 5)
reorder_facets <- function(splret, spl, fulldf, ...) {
ord <- c(1, 3, 4, 2, 5)
make_split_result(
splret$values[ord],
splret$datasplit[ord],
splret$labels[ord]
)
}

# Create a custom split function for adding the new columns (facets) and sorting them
custom_column_split_fun <- make_split_fun(
post = list(
add_combo_facet("all_X",
label = "All Drug X",
levels = c("A: Drug X", "C: Combination")
),
add_combo_facet("all_pt",
label = "All Patients",
levels = c("A: Drug X", "B: Placebo", "C: Combination")
),
reorder_facets
)
)


# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adab <- adab %>%
Expand Down Expand Up @@ -133,12 +153,13 @@ adab_pb <- df_explicit_na(adab) %>%
## {{< fa regular file-lines sm fw >}} Preview

<!-- skip strict because of https://github.com/insightsengineering/rtables/issues/830 -->

```{r variant1, test = list(result_v1 = "result"), opts.label = ifelse(packageVersion("rtables") < "0.6.6.9011", "skip_test_strict", "")}
# Layout for Baseline Prevalence of NAbs
lyt_bl <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -169,7 +190,7 @@ lyt_bl <- basic_table(show_colcounts = TRUE) %>%
lyt_pb <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -217,12 +238,6 @@ result_2 <- build_table(lyt_pb, df = adab_pb, alt_counts_df = adsl)
result_1@col_info <- result_2@col_info
result <- rbind(result_1, result_2)

# Change the column order.
result <- cbind_rtables(result[, 1], result[, 3]) %>%
cbind_rtables(result[, 4]) %>%
cbind_rtables(result[, 2]) %>%
cbind_rtables(result[, 5])

main_title(result) <- paste(
"Baseline Prevalence and Incidence of Treatment Emergent ADA"
)
Expand Down
39 changes: 27 additions & 12 deletions book/tables/ADA/adat04a.qmd
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,30 @@ library(tibble)
adsl <- random.cdisc.data::cadsl
adab <- random.cdisc.data::cadab

combodf <- tribble(
~valname, ~label, ~levelcombo, ~exargs,
"all_X", "All Drug X", c("A: Drug X", "C: Combination"), list(),
"all_pt", "All Patients", c("A: Drug X", "B: Placebo", "C: Combination"), list()

# Order needed for the columns is c(1, 3, 4, 2, 5)
reorder_facets <- function(splret, spl, fulldf, ...) {
ord <- c(1, 3, 4, 2, 5)
make_split_result(
splret$values[ord],
splret$datasplit[ord],
splret$labels[ord]
)
}

# Create a custom split function for adding the new columns (facets) and sorting them
custom_column_split_fun <- make_split_fun(
post = list(
add_combo_facet("all_X",
label = "All Drug X",
levels = c("A: Drug X", "C: Combination")
),
add_combo_facet("all_pt",
label = "All Patients",
levels = c("A: Drug X", "B: Placebo", "C: Combination")
),
reorder_facets
)
)

# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
Expand Down Expand Up @@ -160,12 +180,13 @@ adab_pb <- df_explicit_na(adab) %>%
## {{< fa regular file-lines sm fw >}} Preview

<!-- skip strict because of https://github.com/insightsengineering/rtables/issues/830 -->

```{r variant1, test = list(result_v1 = "result"), opts.label = ifelse(packageVersion("rtables") < "0.6.6.9011", "skip_test_strict", "")}
# Layout for Baseline Prevalence of NAbs
lyt_bl <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -194,7 +215,7 @@ lyt_bl <- basic_table(show_colcounts = TRUE) %>%
lyt_pb <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -241,12 +262,6 @@ result_2 <- build_table(lyt_pb, df = adab_pb, alt_counts_df = adsl)
# Combine tables
result <- rbind(result_1, result_2)

# Change the column order
result <- cbind_rtables(result[, 1], result[, 3]) %>%
cbind_rtables(result[, 4]) %>%
cbind_rtables(result[, 2]) %>%
cbind_rtables(result[, 5])

main_title(result) <- paste(
"Baseline Prevalence and Incidence of Treatment Emergent NAbs"
)
Expand Down
38 changes: 26 additions & 12 deletions book/tables/ADA/adat04b.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,29 @@ library(tibble)
adsl <- random.cdisc.data::cadsl
adab <- random.cdisc.data::cadab

combodf <- tribble(
~valname, ~label, ~levelcombo, ~exargs,
"all_X", "All Drug X", c("A: Drug X", "C: Combination"), list(),
"all_pt", "All Patients", c("A: Drug X", "B: Placebo", "C: Combination"), list()
# Order needed for the columns is c(1, 3, 4, 2, 5)
reorder_facets <- function(splret, spl, fulldf, ...) {
ord <- c(1, 3, 4, 2, 5)
make_split_result(
splret$values[ord],
splret$datasplit[ord],
splret$labels[ord]
)
}

# Create a custom split function for adding the new columns (facets) and sorting them
custom_column_split_fun <- make_split_fun(
post = list(
add_combo_facet("all_X",
label = "All Drug X",
levels = c("A: Drug X", "C: Combination")
),
add_combo_facet("all_pt",
label = "All Patients",
levels = c("A: Drug X", "B: Placebo", "C: Combination")
),
reorder_facets
)
)

# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
Expand Down Expand Up @@ -140,12 +159,13 @@ adab_pb <- left_join(adab_pb_ada, adab_pb_adap, by = mergecol) %>%
## {{< fa regular file-lines sm fw >}} Preview

<!-- skip strict because of https://github.com/insightsengineering/rtables/issues/830 -->

```{r variant1, test = list(result_v1 = "result"), opts.label = ifelse(packageVersion("rtables") < "0.6.6.9011", "skip_test_strict", "")}
# Layout for Baseline Prevalence of NAbs
lyt_bl <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -175,7 +195,7 @@ lyt_bl <- basic_table(show_colcounts = TRUE) %>%
lyt_pb <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -207,12 +227,6 @@ result_2 <- build_table(lyt_pb, df = adab_pb, alt_counts_df = adsl)
# Combine tables.
result <- rbind(result_1, result_2)

# Change the column order.
result <- cbind_rtables(result[, 1], result[, 3]) %>%
cbind_rtables(result[, 4]) %>%
cbind_rtables(result[, 2]) %>%
cbind_rtables(result[, 5])

main_title(result) <- paste(
"Baseline Prevalence and Incidence of Neutralizing Antibodies (NAbs)"
)
Expand Down
32 changes: 16 additions & 16 deletions package/tests/testthat/_snaps/stable/tables-ADA-adat01.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
Output
Baseline Prevalence and Incidence of Treatment Emergent ADA

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————
A: Drug X C: Combination <Missing> B: Placebo All Drug X
(N=134) (N=132) (N=0) (N=134) (N=266)
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Baseline Prevalence of ADAs
Baseline evaluable patients 134 132 0 0 266
Patient with a positive sample at baseline 63 (47.0%) 64 (48.5%) 0 0 127 (47.7%)
Patient with no positive samples at baseline 71 68 0 0 139
Incidence of Treatment Emergent ADAs
Post-baseline evaluable patients 134 132 0 0 266
Patient positive for Treatment Emergent ADA 0 0 0 0 0
Treatment-induced ADA 0 0 0 0 0
Treatment-enhanced ADA 0 0 0 0 0
Patient negative for Treatment Emergent ADA 0 0 0 0 0
Treatment unaffected 0 0 0 0 0
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
A: Drug X C: Combination <Missing> B: Placebo All Drug X
(N=134) (N=132) (N=0) (N=134) (N=266)
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Baseline Prevalence of ADAs
Baseline evaluable patients 134 132 0 0 266
Patient with a positive sample at baseline 63 (47.0%) 64 (48.5%) 0 0 127 (47.7%)
Patient with no positive samples at baseline 71 68 0 0 139
Incidence of Treatment Emergent ADAs
Post-baseline evaluable patients 134 132 0 0 266
Patient positive for Treatment Emergent ADA 0 0 0 0 0
Treatment-induced ADA 0 0 0 0 0
Treatment-enhanced ADA 0 0 0 0 0
Patient negative for Treatment Emergent ADA 0 0 0 0 0
Treatment unaffected 0 0 0 0 0
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————

ADA = Anti-Drug Antibodies (is also referred to as ATA, or Anti-Therapeutic Antibodies) Baseline evaluable patient = a patient with an ADA assay result from a baseline sample(s)
Post-baseline evaluable patient = a patient with an ADA assay result from at least one post-baseline sample Number of patients positive for Treatment Emergent
Expand Down
36 changes: 18 additions & 18 deletions package/tests/testthat/_snaps/stable/tables-ADA-adat04a.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
Baseline Prevalence and Incidence of Treatment Emergent NAbs
Protocol: A: Drug X Antibody

————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
A: Drug X C: Combination <Missing> B: Placebo All Drug X
(N=134) (N=132) (N=0) (N=134) (N=266)
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Baseline Prevalence of NAbs
Baseline evaluable patients for ADA 134 132 0 0 266
Patients with a positive ADA sample at baseline 63 64 0 0 127
Patients with a positive NAb sample at baseline 0 0 0 0 0
Patient with no positive NAb samples at baseline 0 0 0 0 0
Incidence of Treatment Emergent NAbs
Post-baseline evaluable patients for ADA 134 132 0 0 266
Patients positive for ADA 66 59 0 0 125
Patients positive for Treatment Emergent NAb 0 0 0 0 0
Treatment-induced NAb 0 0 0 0 0
Treatment-enhanced NAb 0 0 0 0 0
Patients negative for NAb 0 0 0 0 0
Treatment unaffected 0 0 0 0 0
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
A: Drug X C: Combination <Missing> B: Placebo All Drug X
(N=134) (N=132) (N=0) (N=134) (N=266)
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Baseline Prevalence of NAbs
Baseline evaluable patients for ADA 134 132 0 0 266
Patients with a positive ADA sample at baseline 63 64 0 0 127
Patients with a positive NAb sample at baseline 0 0 0 0 0
Patient with no positive NAb samples at baseline 0 0 0 0 0
Incidence of Treatment Emergent NAbs
Post-baseline evaluable patients for ADA 134 132 0 0 266
Patients positive for ADA 66 59 0 0 125
Patients positive for Treatment Emergent NAb 0 0 0 0 0
Treatment-induced NAb 0 0 0 0 0
Treatment-enhanced NAb 0 0 0 0 0
Patients negative for NAb 0 0 0 0 0
Treatment unaffected 0 0 0 0 0
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

NAb = Neutralizing Antibodies ADA = Anti-Drug Antibodies (is also referred to as ATA, or Anti-Therapeutic Antibodies) Baseline evaluable patient for ADA = a patient with an ADA assay result from a baseline sample(s)
Baseline evaluable patient for NAb = a patient with a NAb assay result from a baseline sample(s)
Expand Down
Loading
Loading