kaz-yos / tableone

R package to create "Table 1", description of baseline characteristics with or without propensity score weighting
https://cran.r-project.org/web/packages/tableone/index.html
217 stars 41 forks source link

[BUG report] IF categorical variables is less than 10%, there is a space before the result. #75

Closed WynRtool closed 2 years ago

WynRtool commented 4 years ago

We can find the BUG in the example in https://github.com/kaz-yos/tableone.

library(tableone) data(pbc, package = "survival") vars <- names(pbc)[-1] tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc, factorVars = c("status","edema","stage")) print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), exact = c("status","stage"), smd = TRUE, formatOptions = list(big.mark = ","))

if status = 1 and trt = 1, the result is 10 ( 6.3) , not 10 (6.3). there is an extra space before 6.3.

status (%) 0.884 exact 0.054 0 83 (52.5) 85 (55.2)
1 10 ( 6.3) 9 ( 5.8)
2 65 (41.1) 60 (39.0)

tszberkowitz commented 2 years ago

@WynRtool That's not a bug. Those spaces are added intentionally to vertically align output in a monospace output format, e.g., the R terminal. If you don't want the spaces added (which is often the case when you are going to present the output in a different software), you can specify noSpaces = TRUE argument. From your example, you would use:

print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"),
      exact = c("status","stage"), smd = TRUE,
      formatOptions = list(big.mark = ","),
      noSpaces = TRUE)