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

Bug Report: Number formatting issues with tbl_cross() #1943

Closed
DesiQuintans opened this issue Aug 30, 2024 · 1 comment · Fixed by #1944
Closed

Bug Report: Number formatting issues with tbl_cross() #1943

DesiQuintans opened this issue Aug 30, 2024 · 1 comment · Fixed by #1944

Comments

@DesiQuintans
Copy link

DesiQuintans commented Aug 30, 2024

I've found these two issues in tbl_cross():

  1. 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.
  2. 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

@ddsjoberg
Copy link
Owner

ddsjoberg commented Aug 30, 2024

@DesiQuintans ! Thank you so much for reporting and the reproducible example. This should be fixed in dev. Can you take a look using your data, please?

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

Successfully merging a pull request may close this issue.

2 participants