Skip to content

.in_ref_row variable passed to analyze & co. #165

@anajens

Description

@anajens

Issue originally reported by @danielinteractive

It would be good to have something like a .in_ref_row variable populated that the user can define when defining a row split, similarly as we have .in_ref_col for column split.

Examples:

(1) If we summarize change from baseline ("CHG" variable), we don't want to have 0s displayed when being in the reference row, i.e. baseline visit here:

library(rtables)
library(dplyr)

anl <- ex_adlb %>%
  filter(PARAMCD == "ALT") %>%
  filter(AVISIT != "SCREENING")

basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("AVISIT", split_fun = drop_split_levels) %>%
  analyze("CHG") %>%
  build_table(anl)
                A: Drug X   B: Placebo   C: Combination
-------------------------------------------------------
BASELINE                                               
  Mean              0           0              0       
WEEK 1 DAY 8                                           
  Mean            -0.97        0.14           0.2      
WEEK 2 DAY 15                                          
  Mean            -0.16       -0.06          -2.41     
WEEK 3 DAY 22                                          
  Mean            0.69        -0.63          -2.05     
WEEK 4 DAY 29                                          
  Mean            1.13        -1.04          -1.25     
WEEK 5 DAY 36                                          
  Mean            1.26        -0.59          -0.92 

Proposed code:

basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("AVISIT", ref_level = "BASELINE") %>%
  analyze("CHG", afun = function(x, .in_ref_row) `if`(.in_ref_row, "", mean(x))) %>%
  build_table(anl)
                A: Drug X   B: Placebo   C: Combination
-------------------------------------------------------
BASELINE                                               
  Mean                                                 
WEEK 1 DAY 8                                           
  Mean            -0.97        0.14           0.2      
WEEK 2 DAY 15                                          
  Mean            -0.16       -0.06          -2.41     
WEEK 3 DAY 22                                          
  Mean            0.69        -0.63          -2.05     
WEEK 4 DAY 29                                          
  Mean            1.13        -1.04          -1.25     
WEEK 5 DAY 36                                          
  Mean            1.26        -0.59          -0.92 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions