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

[Feature Request]: Option to specify .labels and .formats from tern #1130

Open
3 tasks done
crystalluckett-sanofi opened this issue Apr 22, 2024 · 5 comments
Open
3 tasks done
Labels
enhancement New feature or request sme

Comments

@crystalluckett-sanofi
Copy link

Feature description

As an example, it is possible to customize the labels and formats in the tern table functions:

library(tern)
dta_test <- data.frame(
  USUBJID = rep(1:6, each = 3),
  PARAMCD = rep("lab", 6 * 3),
  AVISIT  = rep(paste0("V", 1:3), 6),
  ARM     = rep(LETTERS[1:3], rep(6, 3)),
  AVAL    = c(9:1, rep(NA, 9))
)
l <- basic_table() %>%
  split_cols_by(var = "ARM") %>%
  split_rows_by(var = "AVISIT") %>%
  analyze_vars(
    vars = "AVAL",
    .formats = c("range" = "(xx.x, xx.x)"),
    .labels = c("range" = "(Min, Max)")
  )
build_table(l, df = dta_test)

However, there's no such option available in the TMC equivalent, tm_t_summary_by.
It would be nice if these could be specified across all table modules, and, even better, if a set of defaults could be specified that is applied to all tables, similar to tern:::summary_formats() and tern:::summary_labels().

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@crystalluckett-sanofi crystalluckett-sanofi added the enhancement New feature or request label Apr 22, 2024
@donyunardi donyunardi added the sme label May 17, 2024
@Melkiades
Copy link
Contributor

Thanks for the nice question! You can do what you want in two ways:

  1. Add your personal formats and labels directly to analyze_vars in the template_summary_by, reinstall {teal.modules.clinical} and they will appear in your app. You can also check the stats bindings from the following
shiny::checkboxGroupInput(
            ns("numeric_stats"),
            label = "Choose the statistics to display for numeric variables",
            choices = c(
              "n" = "n",
              "Mean (SD)" = "mean_sd",
              "Mean 95% CI" = "mean_ci",
              "Geometric Mean" = "geom_mean",
              "Median" = "median",
              "Median 95% CI" = "median_ci",
              "25% and 75%-ile" = "quantiles",
              "Min - Max" = "range"
            ),
            selected = a$numeric_stats
          )
  1. Keeping in mind the above binding labels (mean_sd etc) you can change the defaults on your local by overloading tern::tern_default_formats and/or tern::tern_default_labels (I would change only what you need so not to mess it up too much)

As a final note, I do not think that, for now, we have plans to make accessible from the UI to customize labels. Right @donyunardi?

@donyunardi
Copy link
Contributor

Not yet, but this something that we're thinking as well.
We want the teal_module to be flexible for user to extend and customize the output.

This issue might be related with insightsengineering/teal#1384

@crystalluckett-sanofi
Copy link
Author

@Melkiades sorry for the very late reply on this.

I guess the solution you've provided would technically work, but I was looking for something a little more functional.
For example, I may have one application where I want to round the mean to 2 decimals and another application where I want to round to 3 decimals instead. I would have to maintain multiple templates, one for each app?

Since there are options in tern, why not expose arguments in the module function as well? Perhaps with a new function argument like

tern_args = list(
   .formats = c("range" = "(xx.x, xx.x)"),
    .labels = c("range" = "(Min, Max)")
)

and then passing these args into analyze_vars?

@Melkiades
Copy link
Contributor

@Melkiades sorry for the very late reply on this.

I guess the solution you've provided would technically work, but I was looking for something a little more functional. For example, I may have one application where I want to round the mean to 2 decimals and another application where I want to round to 3 decimals instead. I would have to maintain multiple templates, one for each app?

Since there are options in tern, why not expose arguments in the module function as well? Perhaps with a new function argument like

tern_args = list(
   .formats = c("range" = "(xx.x, xx.x)"),
    .labels = c("range" = "(Min, Max)")
)

and then passing these args into analyze_vars?

You can probably define different stats names (still referring to the same stats) and then change the formats. Still you need this info to be accessible from the GUI

@crystalluckett-sanofi
Copy link
Author

I guess I'm not so much concerned with having these options available in the UI, but just in the actual function itself when configuring the module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sme
Projects
None yet
Development

No branches or pull requests

3 participants