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

Add documentation about named lists in tbl_summary(digits) #1948

Open
ddsjoberg opened this issue Sep 3, 2024 · 1 comment
Open

Add documentation about named lists in tbl_summary(digits) #1948

ddsjoberg opened this issue Sep 3, 2024 · 1 comment

Comments

@ddsjoberg
Copy link
Owner

ddsjoberg commented Sep 3, 2024

FIRST, we also need to evaluate how we can use the named lists in digits to modify the missing row stats. I think it works if the digits are all named lists (no tidy select, maybe). Minimally it may work with tidyselect, but probably not with the recycling to fill the vector length.

Once we figure out what code will and will not work, then we can update the documentation

@ddsjoberg
Copy link
Owner Author

Here are a few examples of using the digits argument to change the formatting of the missing stats.

I think I am only confident in urging users to pass named lists. Anything else just seems too fragile. Rather than documenting this in tbl_summary() help file, I think an example to gallery.Rmd is enough.

library(gtsummary)
packageVersion("gtsummary")
#> [1] '2.0.2.9000'

# using named lists in `digits` works for primary stats and missing stats
tbl_summary(
  trial, 
  include = c(age, response),
  missing = "always",
  missing_stat = "{N_miss} ({p_miss}%)",
  digits = list(age = list(p_miss = 2),
                response = list(p = 1, p_miss = 2))
) |> 
  as_kable()
Characteristic N = 200
Age 47 (38, 57)
Unknown 11 (5.50%)
Tumor Response 61 (31.6%)
Unknown 7 (3.50%)
# this is a good results, but i am not sure how fragile it is
tbl_summary(
  trial, 
  include = age,
  missing = "always",
  missing_stat = "{N_miss} ({p_miss}%)",
  digits = age ~ list(2, p_miss = 2)
) |> 
  as_kable()
Characteristic N = 200
Age 47.00 (38.00, 57.00)
Unknown 11 (5.5%)
# this is a nonsense result
tbl_summary(
  trial, 
  include = age,
  missing = "always",
  missing_stat = "{N_miss} ({p_miss}%)",
  digits = age ~ c(2, 0, 0, 4, p_miss = 2)
) |> 
  as_kable()
Characteristic N = 200
Age 47.00 (38, 57)
Unknown 11 (5.5%)
# this is a nonsense result
tbl_summary(
  trial, 
  include = age,
  missing = "always",
  missing_stat = "{N_miss} ({p_miss}%)",
  digits = age ~ c(2, p_miss = 2, 0, 0, 4)
) |> 
  as_kable()
Characteristic N = 200
Age 47.00 (38.00, 57)
Unknown 11 (5.5%)

Created on 2024-09-09 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant