pharmaverse / pharmaverse/rtables

Split name missing from cur_col_id in split context

Open
#763 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

sme
Dominant language
R
Stars
260
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Currently the cur_col_idin the split context is pasted together from only the values of the column path the tabulation machinery is currently at.

This information is incomplete, particularly in cases where there are different facets in column space based on the same variable, e.g,

DM2 <- DM
DM2$active_trt <- factor(ifelse(DM2$ARM == "C: Combination", " ", "Cool Category"),
                         levels = c("Cool Category", " "))

myfun <- function(x, .N_col, .spl_context) {
    colid <- .spl_context$cur_col_id[[1]]
    print(colid)
    if(grepl(".", colid, fixed = TRUE))
        rcell(length(x)*c(1, 1/.N_col), format = "xx (xx.x%)")
    else
        rcell("some other stuff")
}

lyt3 <- basic_table() %>%
    split_cols_by("active_trt", split_fun = trim_levels_in_group("ARM")) %>%
    split_cols_by("ARM") %>%
    split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "C: Combination")),
                  nested = FALSE) %>%
    split_rows_by("STRATA1") %>%
    analyze("ID", myfun)


build_table(lyt3, DM2)

gives us

[1] "Cool Category.A: Drug X"
[1] "Cool Category.B: Placebo"
[1] " .C: Combination"
[1] "A: Drug X"
[1] "C: Combination"
[1] "Cool Category.A: Drug X"
[1] "Cool Category.B: Placebo"
[1] " .C: Combination"
[1] "A: Drug X"
[1] "C: Combination"
[1] "Cool Category.A: Drug X"
[1] "Cool Category.B: Placebo"
[1] " .C: Combination"
[1] "A: Drug X"
[1] "C: Combination"
               Cool Category                                                            
          A: Drug X    B: Placebo   C: Combination      A: Drug X        C: Combination 
————————————————————————————————————————————————————————————————————————————————————————
A                                                                                       
  myfun   36 (29.8%)   33 (31.1%)     45 (34.9%)     some other stuff   some other stuff
B                                                                                       
  myfun   41 (33.9%)   40 (37.7%)     38 (29.5%)     some other stuff   some other stuff
C                                                                                       
  myfun   44 (36.4%)   33 (31.1%)     46 (35.7%)     some other stuff   some other stuff

Note I was able to monkey-hack something together here, but having access to the full path, either in pasted form in cur_col_id or preferably, imo, in a separate list column, would be a cleaner solution more in line with all of the o ther path-based interactions rtables supports

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the split-context handling exercised by build_table and trace how cur_col_id is assembled from the current column path. Use the supplied lyt3 example to determine how the full path should be exposed so facets based on the same variable remain distinguishable, then verify the resulting identifiers or path data across the repeated splits.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.