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

Split name missing from cur_col_id in split context #763

Open
gmbecker opened this issue Oct 27, 2023 · 2 comments
Open

Split name missing from cur_col_id in split context #763

gmbecker opened this issue Oct 27, 2023 · 2 comments
Labels

Comments

@gmbecker
Copy link
Collaborator

gmbecker commented Oct 27, 2023

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

@Melkiades
Copy link
Contributor

I think the path is available here: .spl_context$cur_col_split_val or .spl_context$cur_col_split. We could discuss having a .spl_context_rows and .splt_context_cols (and maybe making it an object with rows and cols getter/setters) but at the moment I do not know if it is worth the added complexity

@Melkiades Melkiades added the sme label Oct 31, 2023
@gmbecker
Copy link
Collaborator Author

@Melkiades unfortunately the current split and value are not sufficient. In the example I put above (which I can now say is a set of relative risk columns, since I found out that came from public FDA specs), I effectively need to know whether the current column split has a parent split or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants