Skip to content

ref_group should not be limited to displayed split levels #1116

Description

@wwojciech

Currently, ref_group appears to require the reference level to be included in the levels retained by split_fun. For example:

table(DM$ARM)

     A: Drug X     B: Placebo C: Combination 
           121            106            129

lyt <- basic_table() |>
  split_cols_by(
    "ARM",
    split_fun = keep_split_levels("A: Drug X"),
    ref_group = "B: Placebo"
  ) |>
  analyze("AGE")

build_table(lyt, DM)

results in:

Error in .add_ref_extras(spl, df, ret) : length(ref_ind) == 1 is not TRUE

From the user perspective, this seems to be an unnecessary and unreasonable limitation. I think ref_group should be allowed to be any valid level of the split variable, even if that level is not displayed or not observed in the data.

This includes:

  • A factor level that exists but is not observed in the data.
  • A factor level that is not present at all - in this case, perhaps a warning would be appropriate.

Simply put, the split function controls what is displayed, while ref_group should be allowed to specify the reference level independently.

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