Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lcomm opened this issue Jan 26, 2022 · 1 comment
Labels
bug Something isn't working issue Used for project filtering

Comments

@lcomm
Copy link

lcomm commented Jan 26, 2022

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
@lcomm lcomm added bug Something isn't working issue Used for project filtering labels Jan 26, 2022
@lcomm
Copy link
Author

lcomm commented Jan 27, 2022

I forgot to mention that if you indicate a preference between the solution ideas, I am willing to attempt the bugfix myself. But it does require a bit of a design decision about how prescriptive vs. flexible to make the visr.attrition method. Are you willing to assume the only column name options are "Remaining N" and "Remaining %"? For percentage reporting, are you willing to force users to report 2 and only 2 digits past the decimal point, or do you want them to be able to choose that for themselves?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working issue Used for project filtering
Projects
None yet
Development

No branches or pull requests

1 participant