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

pandoc.table doesn't render rownames when they start with 1 #310

Closed alansz closed 7 years ago

alansz commented 7 years ago

Using: pander 0.6.1 under R3.3.1

When table row names are 1:nrow(x), they are not rendered by pandoc.table even when explicitly given by row.names.

To replicate:

tst<-data.frame(level=c(1,1,2,2,3,3),value=c('Y','Y','N','Y','N','Y'))
table(tst$level,tst$value)
rownames(table(tst$level,tst$value))
# Shows row names 1, 2, 3
# But:
pandoc.table(table(tst$level,tst$value),row.names=1:3)
# Produces:
# -------
# N   Y 
# --- ---
# 0   2 
# 1   1 
# 1   1 
# -------

I have found no way to force pandoc.table to show row names when they happen to be 1:nrow(x).

daroczig commented 7 years ago

That's because, by default, the "obvious" row names are removed at https://github.com/Rapporter/pander/blob/master/R/pandoc.R#L1133

If you don't like this behavior, you could add some whitespace to the row names that will be removed anyway:

> pander(table(tst$level,tst$value),row.names = paste('', 1:3))

----------------
 &nbsp;   N   Y 
-------- --- ---
 **1**    0   2 

 **2**    1   1 

 **3**    1   1 
----------------

But I'm happy to update the codebase not to remove obvious rownames if that's provided manually. Let me know if that suggestion makes sense to you.

alansz commented 7 years ago

I would have expected that if I gave row names explicitly, they'd be used, even if they were obvious, so I agree with your suggestion not to remove them when provided manually. Thanks!