pharmaverse / pharmaverse/rtables
`.spl_context` has 0 rows and missing columns when no row split is defined.
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 260
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I’m writing a custom cfun whose behavior depends on the current column, but .spl_context is empty when there is no row-split defined. See below:
c_test <- function(x, labelstr = "", .spl_context) {
cat("nrow(.spl_context) is:", nrow(.spl_context), "\n")
cat("colnames(.spl_context) are:", colnames(.spl_context), "\n\n")
rcell(1, label = labelstr)
}
lyt <- basic_table() |>
split_cols_by("ARM") |>
summarize_row_groups(format = NULL, cfun = c_test)
tbl <- build_table(lyt, DM)
nrow(.spl_context) is: 0
colnames(.spl_context) are: split value full_parent_df all_cols_n A: Drug X B: Placebo C: Combination
nrow(.spl_context) is: 0
colnames(.spl_context) are: split value full_parent_df all_cols_n A: Drug X B: Placebo C: Combination
nrow(.spl_context) is: 0
colnames(.spl_context) are: split value full_parent_df all_cols_n A: Drug X B: Drug X B: Placebo C: Combination
I’m wondering what the reasoning is behind the fact that, when there is no row split in the layout, .spl_context has 0 rows and some of its usual columns are missing. Is this the expected behavior? I would have expected .spl_context to contain all of its usual columns, and also with a single row representing the root row-split context.
I understand that using summarize_row_groups() without any row split in the layout is a legitimate use case. For example:
lyt2 <- basic_table() |>
split_cols_by("ARM") |>
summarize_row_groups(label_fstr = "Overall")
tbl2 <- build_table(lyt2, DM)
tbl2
A: Drug X B: Placebo C: Combination
——————————————————————————————————————————————————————
Overall 121 (100.0%) 106 (100.0%) 129 (100.0%)
In this case, summarize_row_groups() is effectively operating at the root level, so I would expect the root context to be represented in .spl_context, even though there are no row splits.
PS. I know I can work around this by using analyze(some_var, afun = c_test).
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 by tracing how summarize_row_groups() constructs .spl_context when the layout has no row split, using the reported examples as the expected case. Check existing coverage for root-level contexts and define done as a context with the usual columns and one root row when summarize_row_groups() operates at the root level.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100