pharmaverse / pharmaverse/rtables

[Bug]: Accessing columns by path doesn't work when table has an overall column.

Open
#908 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Using the example found here (minus the secondary column splitting split_cols_by("SEX")):

.simpleCap <- function(x) {
  if (length(x) > 1) {
    return(sapply(x, .simpleCap))
  }
  s <- strsplit(tolower(x), " ")[[1]]
  paste(toupper(substring(s, 1, 1)), substring(s, 2), sep = "", collapse = " ")
}

adsl2 <- ex_adsl |>
  filter(SEX %in% c("M", "F") & RACE %in% (levels(RACE)[1:3])) |>
  mutate(ethnicity = .simpleCap(gsub("(.*)OR.*", "\\1", RACE)), RACE = factor(RACE))

lyt2 <- basic_table() |>
  split_cols_by("ARM") |>
  split_rows_by("RACE", labels_var = "ethnicity", split_fun = drop_split_levels) |>
  summarize_row_groups() |>
  analyze(c("AGE", "STRATA1"))

tbl2 <- build_table(lyt2, adsl2)

tbl2
#             A: Drug X    B: Placebo   C: Combination
# ————————————————————————————————————————————————————
# Asian       66 (54.1%)   66 (55.5%)     71 (59.2%)  
#   AGE                                               
#     Mean      32.50        36.68          36.99     
#   STRATA1                                           
#     A           21           24             18      
#     B           20           22             25      
#     C           25           20             28      
# Black       30 (24.6%)   28 (23.5%)     28 (23.3%)  
#   AGE                                               
#     Mean      34.27        34.93          33.71     
#   STRATA1                                           
#     A           7            11             10      
#     B           11           7              8       
#     C           12           10             10      
# White       26 (21.3%)   25 (21.0%)     21 (17.5%)  
#   AGE                                               
#     Mean      36.15        33.12          31.95     
#   STRATA1                                           
#     A           8            6              8       
#     B           9            12             7       
#     C           9            7              6 

Adding a column footnote works for this, for example:

col_paths_summary(tbl2)
# label             path               
# —————————————————————————————————————
# A: Drug X         ARM, A: Drug X     
# B: Placebo        ARM, B: Placebo    
# C: Combination    ARM, C: Combination
fnotes_at_path(tbl2, rowpath = NULL, c("ARM", "B: Placebo")) <- c("this is a placebo")
tbl2
#             A: Drug X    B: Placebo {1}   C: Combination
# ————————————————————————————————————————————————————————
# Asian       66 (54.1%)     66 (55.5%)       71 (59.2%)  
#   AGE                                                   
#     Mean      32.50          36.68            36.99     
# ...
#     C           9              7                6       
# ————————————————————————————————————————————————————————

# {1} - this is a placebo
# ————————————————————————————————————————————————————————

However, if we add an overall column, this no longer works:

lyt3 <- lyt2 |> add_overall_col("Total")
tbl3 <- build_table(lyt3, adsl2)
tbl3
#             A: Drug X    B: Placebo   C: Combination      Total   
# ——————————————————————————————————————————————————————————————————
# Asian       66 (54.1%)   66 (55.5%)     71 (59.2%)     203 (56.2%)
#   AGE                                                             
#     Mean      32.50        36.68          36.99           35.43   
# ...
#     C           9            7              6              22  
col_paths_summary(tbl3)
# label             path               
# —————————————————————————————————————
# A: Drug X         ARM, A: Drug X     
# B: Placebo        ARM, B: Placebo    
# C: Combination    ARM, C: Combination
# Total             Total, Total
fnotes_at_path(tbl3, rowpath = NULL, c("ARM", "B: Placebo")) <- c("this is a placebo")
# Error in col_fnotes_at_path(coltree(ttrp), colpath, fnotes = value) : 
#   Path appears invalid at step: ARM

Also, possibly related, note that the actual example found here has its footnote numbered as NA in the output found in the article.

I encounter this using rtables 0.6.9 installed from CRAN as well as v0.6.9.9005 installed from GitHub.

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

Reproduce the failure with the issue's lyt3, build_table, col_paths_summary, and fnotes_at_path example, starting by comparing the column paths before and after add_overall_col("Total"). Trace how fnotes_at_path resolves the requested ARM path when the overall column is present; done means the placebo footnote attaches successfully and the related footnote numbering issue is clarified or fixed.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.