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 2 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
47 changes: 30 additions & 17 deletions book/tables/ADA/adat01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ subtitle: Baseline Prevalence and Incidence of Treatment Emergent ADA

{{< include ../../_utils/envir_hook.qmd >}}

:::: {.panel-tabset}
::: panel-tabset
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
## Data Setup

```{r setup, message = FALSE}
Expand All @@ -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 All @@ -239,8 +254,7 @@ main_footer(result) <- "ADA = Anti-Drug Antibodies (is also referred to as ATA,
result
```

`r webr_code_labels <- c("setup", "variant1")`
{{< include ../../_utils/webr.qmd >}}
`r webr_code_labels <- c("setup", "variant1")` {{< include ../../_utils/webr.qmd >}}
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
:::

{{< include ../../_utils/save_results.qmd >}}
Expand All @@ -254,5 +268,4 @@ result
```

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

::::
:::
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 30 additions & 11 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 @@ -7,7 +7,7 @@ subtitle: Baseline Prevalence and Incidence of Treatment Emergent NAbs

{{< include ../../_utils/envir_hook.qmd >}}

:::: {.panel-tabset}
::: panel-tabset
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
## Data Setup

```{r setup, message = FALSE}
Expand All @@ -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 @@ -265,8 +286,7 @@ Treatment unaffected = A post-baseline evaluable patient with a positive result
result
```

`r webr_code_labels <- c("setup", "variant1")`
{{< include ../../_utils/webr.qmd >}}
`r webr_code_labels <- c("setup", "variant1")` {{< include ../../_utils/webr.qmd >}}
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
:::

{{< include ../../_utils/save_results.qmd >}}
Expand All @@ -280,5 +300,4 @@ result
```

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

::::
:::
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 34 additions & 16 deletions book/tables/ADA/adat04b.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ subtitle: Baseline Prevalence and Incidence of NAbs

{{< include ../../_utils/envir_hook.qmd >}}

:::: {.panel-tabset}
::: panel-tabset
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
## Data Setup

```{r setup, message = FALSE}
Expand All @@ -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,11 +227,11 @@ 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])
# # Change the column order.
# result <- cbind_rtables(result[, 1], result[, 3]) %>%
# cbind_rtables(result[, 4]) %>%
# cbind_rtables(result[, 2]) %>%
# cbind_rtables(result[, 5])
Melkiades marked this conversation as resolved.
Show resolved Hide resolved

main_title(result) <- paste(
"Baseline Prevalence and Incidence of Neutralizing Antibodies (NAbs)"
Expand All @@ -224,8 +244,7 @@ Number of patients positive for NAb = the number (and percentage) of post-baseli
result
```

`r webr_code_labels <- c("setup", "variant1")`
{{< include ../../_utils/webr.qmd >}}
`r webr_code_labels <- c("setup", "variant1")` {{< include ../../_utils/webr.qmd >}}
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
:::

{{< include ../../_utils/save_results.qmd >}}
Expand All @@ -239,5 +258,4 @@ result
```

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

::::
:::
Melkiades marked this conversation as resolved.
Show resolved Hide resolved