gtsummary
gtsummary copied to clipboard
Bug Report: Number formatting issues with `tbl_cross()`
I've found these two issues in tbl_cross()
:
- The
digits =
argument doesn't seem to be respected. In the reprex below, I try to add 4 decimal places to the{p}
statistic item with no effect. - In
statistic =
, the{n}
flag is correctly styled with a big mark ("1,011") and so is{N_nonmiss}
, but{N}
is not (comes out as "3000").
Thank you for your work on an excellent package <3
library(gtsummary)
sessionInfo()$otherPkgs$gtsummary$Version
#> [1] "2.0.1"
set.seed(12345)
my_data <-
data.frame(
states = sample(c(state.name[1:4], NA), size = 3000, replace = TRUE),
fruits = sample(c("Apple", "Tomato"), size = 3000, replace = TRUE)
)
tbl_cross(
my_data,
row = states,
col = fruits,
statistic = "{n}/{N_nonmiss}/{N} ({p}%)",
digits = c(0, 0, 0, 4)
)
fruits | Total | ||
---|---|---|---|
Apple | Tomato | ||
states | |||
Alabama | 303/1,504/3000 (10%) | 329/1,496/3000 (11%) | 632/3,000/3000 (21%) |
Alaska | 313/1,504/3000 (10%) | 273/1,496/3000 (9.1%) | 586/3,000/3000 (20%) |
Arizona | 322/1,504/3000 (11%) | 288/1,496/3000 (9.6%) | 610/3,000/3000 (20%) |
Arkansas | 279/1,504/3000 (9.3%) | 308/1,496/3000 (10%) | 587/3,000/3000 (20%) |
Unknown | 287/1,504/3000 (9.6%) | 298/1,496/3000 (9.9%) | 585/3,000/3000 (20%) |
Total | 1,504/1,504/3000 (50%) | 1,496/1,496/3000 (50%) | 3,000/3,000/3000 (100%) |
Created on 2024-08-30 with reprex v2.1.1