Skip to content

Improve messaging in ard_stats_paired_wilcox_test() when a subject has more than two observations #295

@ddsjoberg

Description

@ddsjoberg

The warning messaging is being thrown from the pivoting of the table, but we can do better than that!

We should throw an error before we even attempt the pivot.

tmax <- data.frame(Subject = c(1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 5, 5, 5, 5), 
                   Treatment = c("T", "R", "T", "R", "R", "T", "R", "T", "T", "R", "T", "R", "R", "T", "R", "T"), 
                   TMAX = c(1.333, 1.667, 0.667, 1.667, 2, 0.667, 2, 2, 1, 1, 2, 1, 0.667, 1, 2, 1))

cardx::ard_stats_paired_wilcox_test(
  data = tmax, by = Treatment, variables = TMAX, id = Subject
) |> 
  dplyr::pull(warning) |> 
  unique()
#> [[1]]
#> [1] "Values from `TMAX` are not uniquely identified; output will contain list-cols.\n• Use `values_fn = list` to suppress this warning.\n• Use `values_fn = {summary_fun}` to summarise duplicates.\n• Use the following dplyr code to identify duplicates.\n  {data} |>\n  dplyr::summarise(n = dplyr::n(), .by = c(Subject, Treatment)) |>\n  dplyr::filter(n > 1L)"

Created on 2025-05-04 with reprex v2.1.1

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