Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

pander errors with descr::CrossTables if table has no row or col % #278

Open ebergel opened 7 years ago

ebergel commented 7 years ago

When using pander with descr::CrossTables, the generated markdown creates a table with duplicated row names.

see also post in here

This code:

x<- c('aaa','bbb','ccc')
y<- c('ddd', 'eee', 'fff')  
t1 <- descr::CrossTable(x = x, y = y,
                        prop.c = FALSE,
                        prop.t = FALSE,
                        prop.r = FALSE,
                        prop.chisq = FALSE, 
                        dnn = c('xlabel', 'ylabel'))  
pander::pander(t1, digits = 1) 

generates this markdown

-------------------------------------------------
 &nbsp;\   ylabel\   &nbsp;\   &nbsp;\   &nbsp;\ 
 xlabel      ddd       eee       fff      Total  
--------- --------- --------- --------- ---------
**aaa**\  &nbsp;\   &nbsp;\   &nbsp;\   &nbsp;\  
   N\         1         0         0         1    
  bbb\                                           
   aaa                                           

**bbb**\  &nbsp;\   &nbsp;\   &nbsp;\   &nbsp;\  
   N\         0         1         0         1    
  ccc\                                           
   bbb                                           

**ccc**\  &nbsp;\   &nbsp;\   &nbsp;\   &nbsp;\  
   N\         0         0         1         1    
 Total\                                          
   ccc                                           

  Total       1         1         1         3    
-------------------------------------------------

See the repeated row labels bbb\ aaa on each row header.

For reference, if at least one % is requested, then the table is ok

This code:

t1 <- descr::CrossTable(x = x, y = y,
                        prop.c = FALSE  ,
                        prop.t = FALSE,
                        prop.chisq = FALSE, 
                        dnn = c('xlabel', 'ylabel'))  
pander::pander(t1, digits = 1)

generates this markdown, without errors.

-------------------------------------------------
 &nbsp;\   ylabel\   &nbsp;\   &nbsp;\   &nbsp;\ 
 xlabel      ddd       eee       fff      Total  
--------- --------- --------- --------- ---------
**aaa**\  &nbsp;\   &nbsp;\   &nbsp;\   &nbsp;\  
   N\       1\        0\        0\        1\     
 Row(%)    100.0%     0.0%      0.0%      33.3%  

**bbb**\  &nbsp;\   &nbsp;\   &nbsp;\   &nbsp;\  
   N\       0\        1\        0\        1\     
 Row(%)     0.0%     100.0%     0.0%      33.3%  

**ccc**\  &nbsp;\   &nbsp;\   &nbsp;\   &nbsp;\  
   N\       0\        0\        1\        1\     
 Row(%)     0.0%      0.0%     100.0%     33.3%  

  Total       1         1         1         3    
-------------------------------------------------
daroczig commented 7 years ago

Thanks for reporting this. @RomanTsegelskyi, if you have time, pls look into this as you worked on the function, if not, I'll try to resolve this -- or a related PR is highly welcomed.

RomanTsegelskyi commented 7 years ago

Hi, this definitely seems like a bug, I will try to look into it during the weekend

ebergel commented 7 years ago

Any news on fixing this problems?

dchiu911 commented 5 years ago

Any updates regarding this issue?

daroczig commented 5 years ago

It's not likely that I will have time to look into this soon, sorry, but would appreciate a PR.