Skip to content

Attrition diagram labelling only works for integers and applies label of "N =" #313

@lcomm

Description

@lcomm

Issue description

In theory, attrition diagrams accommodate arbitrary column names for value_column_name, so long as they are valid columns in the attrition table object. But string formatting prevents attrition diagrams from printing percentages, even when they are the pre-calculated format from the get_attrition function.

Steps to reproduce the issue

Minimal reproducible code below. Note that changing value_column_name from "Remaining %" to "Remaining N" produces a diagram as expected.

ad <- visR::get_attrition(visR::adtte,
                    criteria_descriptions = c("1. Not in Placebo Group",
                                              "2. Be 75 years of age or older.",
                                              "3. White",
                                              "4. Female"),
                    criteria_conditions   = c("TRTP != 'Placebo'",
                                              "AGE >= 75",
                                              "RACE=='WHITE'",
                                              "SEX=='F'"),
                    subject_column_name   = "USUBJID")
visR::visr(ad, description_column_name = "Criteria", value_column_name = "Remaining %")

What's the expected result?

An attrition diagram that reports included and excluded patients in terms of percentage of the initial study population.

What's the actual result?

No diagram is produced, and I get the following error message:

Error: Problem with `mutate()` column `label`.
ℹ `label = sprintf("%s\nN = %d", label, get(value_column_name))`.
x invalid format '%d'; use format %f, %e, %g or %a for numeric objects
ℹ The error occurred in row 2.

Additional details / screenshot

image

I believe the problem arises from applying the following sprintf within the .get_labels internal:

dplyr::mutate(label = sprintf("%s\nN = %d", label, get(value_column_name)))
Solution ideas
  • Allow users to specify their own sprintf template to visr.attrition , perhaps with "%s\nN = %d" as the default
  • Within .get_labels, check whether value_column_name contains integers, and apply N-based labelling if so and %-based labelling (e.g., "%s\n%.2f%%") otherwise

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingissueUsed for project filtering

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions