benjaminrich / table1

79 stars 26 forks source link

`t1flex()` causes errors when more than one header column has the same N #103

Closed billdenney closed 11 months ago

billdenney commented 1 year ago

In the example below, it seems like duplicate N cause an issue with the flextable creation.

library(table1)
#> 
#> Attaching package: 'table1'
#> The following objects are masked from 'package:base':
#> 
#>     units, units<-

foo <- data.frame(A = rep(1:2, each = 3), B = rep(1:3, each = 2), C = 1:6)
mytab <- table1(~C|A+B, data = foo)
#> Warning in table1.formula(~C | A + B, data = foo): Terms to the right of '|' in
#> formula 'x' define table columns and are expected to be factors with meaningful
#> labels.
t1flex(mytab)
#> Error in flextable(data): duplicated col_keys: 2
#> (N=1), 1
#> (N=2), 3
#> (N=2)

Created on 2023-03-15 with reprex v2.0.2

benjaminrich commented 1 year ago

Thanks for bringing this to my attention. I wasn't aware of this issue. I'll try to look for a solution.

benjaminrich commented 1 year ago

I've found a solution, and created a PR (#105).

billdenney commented 1 year ago

Thanks!