pharmaverse / pharmaverse/rtables
add_overall_col does not inherit colcounts from previous split
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 260
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
I would like to display N=xx for a total column but this option is not available from the function:
adsl <- data.frame(
ARM = c("Placebo", "Placebo", "Treatment A", "Treatment A", "Treatment B", "Treatment B"),
AGE = c(25, 30, 22, 28, 19, 45),
SEX = c("Male", "Female", "Male", "Female", "Female", "Female")
)
add_combo <- rtables::add_combo_facet(
"Combined",
label = "Combined",
levels = c("Treatment A", "Treatment B")
)
rm_combo_from_placebo <- cond_rm_facets(
facets = "Combined",
ancestor_pos = NA,
value = " ",
split = "ARM"
)
mysplit <- make_split_fun(post = list(add_combo, rm_combo_from_placebo))
basic_table() %>%
split_cols_by("ARM", split_fun = mysplit, show_colcounts = TRUE, colcount_format = "N=xx") %>%
add_overall_col("Total") %>%
append_topleft("Mean Age \\super a") %>%
analyze("AGE") %>%
build_table(df = adsl)
Placebo Treatment A Treatment B Combined
Mean Age \super a N=2 N=2 N=2 N=4 Total
——————————————————————————————————————————————————————————————————————————
Mean 27.50 25.00 32.00 28.50 28.17
The only way of displaying the N = xx is to pass the arguments to basic_table, which is not always desired. Can add_overall_col be updated to fix this?
basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>%
split_cols_by("ARM", split_fun = mysplit) %>%
add_overall_col("Total") %>%
append_topleft("Mean Age \\super a") %>%
analyze("AGE") %>%
build_table(df = adsl)
Placebo Treatment A Treatment B Combined Total
Mean Age \super a N=2 N=2 N=2 N=4 N=6
——————————————————————————————————————————————————————————————————————————
Mean 27.50 25.00 32.00 28.50 28.17
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the add_overall_col and basic_table behavior shown in the reproduction, comparing the two example pipelines. Confirm that a Total column inherits show_colcounts and colcount_format from the preceding split, and verify that the rendered Total column displays N=6 without changing the existing subgroup counts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100