pander icon indicating copy to clipboard operation
pander copied to clipboard

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

Open ebergel opened this issue 9 years ago • 5 comments

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    
-------------------------------------------------

ebergel avatar Sep 19 '16 16:09 ebergel

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.

daroczig avatar Sep 19 '16 19:09 daroczig

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

romantseg avatar Sep 20 '16 09:09 romantseg

Any news on fixing this problems?

ebergel avatar Dec 05 '16 12:12 ebergel

Any updates regarding this issue?

dchiu911 avatar Oct 16 '18 22:10 dchiu911

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

daroczig avatar Oct 16 '18 22:10 daroczig