Skip to content

Commit

Permalink
Fix reorder columns (#256)
Browse files Browse the repository at this point in the history
#255

---------

Signed-off-by: Davide Garolini <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Melkiades and github-actions[bot] authored Jul 24, 2024
1 parent 414372f commit 4113d9a
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 222 deletions.
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
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
7 changes: 5 additions & 2 deletions book/tables/efficacy/rbmit01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ draws_vars$subjid <- "TMP_ID"
Define which imputation method to use, then create samples for the imputation parameters by running the `draws()` function.

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

```{r, warning = FALSE, opts.label = "skip_test_strict"}
#| code-fold: show
draws_method <- method_bayes()
draws_method <- method_bayes(seed = 123)
draws_obj <- rbmi::draws(
data = data_full,
Expand Down Expand Up @@ -154,6 +155,7 @@ The next step is to run the analysis model on each imputed dataset.
This is done by defining an analysis function and then calling `rbmi::analyse()` to apply this function to each imputed dataset.

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

```{r, opts.label = "skip_test_strict"}
#| code-fold: show
#| opts_label: "skip_test_strict" #
Expand Down Expand Up @@ -183,6 +185,7 @@ The `rbmi::pool()` function can be used to summarize the analysis results across
Using the `broom::tidy()` function the `rbmi` final results are reshaped.

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

```{r, opts.label = "skip_test_strict"}
#| code-fold: show
Expand Down Expand Up @@ -215,5 +218,5 @@ result
{{< include ../../_utils/save_results.qmd >}}

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

::::

10 changes: 9 additions & 1 deletion package/tests/testthat/_create_test_files.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Script to create test files for all articles in the test book.
# It would not remove existing test files so in case article location or name is changed, the old test file should be removed manually.
# run with `source()`, e.g.:
# source("./tests//testthat/_create_test_files.R")
# source("./tests/testthat/_create_test_files.R")

article_files <- list.files(
test_book_path,
Expand All @@ -12,6 +12,14 @@ article_files <- list.files(
) |>
grep("tables/|listings/|graphs/", x = _, value = TRUE)

excluded_articles <- c(
# Stan is not reproducible on different platforms
# https://mc-stan.org/docs/2_27/reference-manual/reproducibility-chapter.html
"tables/efficacy/rbmit01.qmd"
)

article_files <- setdiff(article_files, excluded_articles)

test_files <- article_files |>
vapply(
X = _,
Expand Down
32 changes: 16 additions & 16 deletions package/tests/testthat/_snaps/development/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
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
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
Loading

0 comments on commit 4113d9a

Please sign in to comment.