Closed GaryDe2 closed 7 years ago
Interesting -- this works fine here with the same (CRAN) version:
> pander(table(mtcars$am, mtcars$cyl))
---------------------
4 6 8
-------- --- --- ----
**0** 3 4 12
**1** 8 3 2
---------------------
I don't know how this could happen on your machine -- I keep thinking if any Windows-specific issues might cause this, but I don't have any ideas right now. I'm on Linux BTW:
> devtools::session_info()
Session info ------------------------------------------------------------------
setting value
version R version 3.4.1 (2017-06-30)
system x86_64, linux-gnu
ui X11
language (EN)
collate en_US.UTF-8
tz Europe/Budapest
date 2017-08-30
Packages ----------------------------------------------------------------------
package * version date source
base * 3.4.1 2017-07-08 local
compiler 3.4.1 2017-07-08 local
datasets * 3.4.1 2017-07-08 local
devtools 1.13.2 2017-06-02 CRAN (R 3.4.0)
digest 0.6.12 2017-01-27 CRAN (R 3.4.0)
graphics * 3.4.1 2017-07-08 local
grDevices * 3.4.1 2017-07-08 local
memoise 1.1.0 2017-04-21 CRAN (R 3.4.0)
methods * 3.4.1 2017-07-08 local
pander * 0.6.1 2017-08-06 CRAN (R 3.4.1)
Rcpp 0.12.11 2017-05-22 CRAN (R 3.4.0)
stats * 3.4.1 2017-07-08 local
tcltk 3.4.1 2017-07-08 local
tools 3.4.1 2017-07-08 local
utils * 3.4.1 2017-07-08 local
withr 1.0.2 2016-06-20 CRAN (R 3.3.1)
I think I just figured why: I had forgotten I used this at some place:
panderOptions('table.alignment.default',
function(df) ifelse(sapply(df, is.numeric), 'right', 'left'))
It seems that without this option it works. But I have no idea why it doesn't work with, and then doesn't know how to fix the alignment AND printing tables together...
Ah, got it -- then it's not a bug in pander
per se. You have to modify the anonymous function used to decide on the alignment, eg:
> panderOptions('table.alignment.default', function(df) ifelse(sapply(as.data.frame(df), is.numeric), 'right', 'left'))
> pander(table(mtcars$am, mtcars$cyl))
---------------------
4 6 8
-------- --- --- ----
**0** 3 4 12
**1** 8 3 2
---------------------
Thanks! Sorry for not having seen that before, it just totally escaped from my mind
When printing a table with pander I obtain an error message
Error in pandoc.table.return(...) : Wrong number of parameters (76 instead of *4*) passed: justify
that I can't understand.Traceback:
If I convert it in data frame beforecalling pander it works, but the format is now other, it isn't Var1 (mpg in exemple) as row names and Var2 (cyl) as column names, but Var1 (mpg) as column 1, Var2 (cyl) as column 2, and frequencies as column 3, what isn't the researched output when printing a table.
Windows 7 Proffessional, Service Pack 1, 32-bits