2

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.

a <- table(mtcars$mpg, mtcars$cyl)
pander(a)

Traceback:

6. stop(sprintf("Wrong number of parameters (%s instead of *%s*) passed: justify", length(justify), length(t.width)))
5. pandoc.table.return(...)
4. cat(pandoc.table.return(...))
3. pandoc.table(x, caption = caption, ...)
2. pander.table(a)
1. pander(a)

What am I doing false? My goal is to print the table in the table format (values of variable 1 as row names, values of variable 2 as column names), and not as it is if I convert the table into a dataframe (values of variable 1 in column 1, values of variable 2 in column 2, frequency in column 3). I know it would work with print, but I would like to have the pander layout because all my other tables (from data frame format) are printed with pander.

Kristofersen
  • 2,736
  • 1
  • 15
  • 31
GaryDe
  • 492
  • 1
  • 5
  • 17
  • 1
    Try to first convert `a` into a data.frame. – Eric Lecoutre Aug 29 '17 at 14:15
  • Already tried, but it print it without the layout I want. I mean it prints with two columns for the values and a third for the frequencies, when I want values of Var1 as rownames, values of Var2 as col names and frequencies at the intersection of both in the table. – GaryDe Aug 29 '17 at 14:25
  • This seems like a bug from an old version of `pander`. Can you please update to the most recent version and open a ticket on GH if the problem still persists? – daroczig Aug 29 '17 at 14:38
  • It still doesn't work by me after the update, even after quitting and reopen R Studio. I don't know what you mean with "open a ticket on git hub" but would be pleased to do so if you explained me what I have to do. – GaryDe Aug 29 '17 at 15:05
  • @GaryDe see the "BugReports" section at https://cran.r-project.org/package=pander or `bug.report(package = 'pander')`. Please provide your `devtools::session_info()` when opening a ticket. – daroczig Aug 30 '17 at 08:51
  • I did it, hope you have all the infos you need and that I did it right ;-) Thanks for the help – GaryDe Aug 30 '17 at 10:24
  • 1
    FTR the related GH ticket we sorted out this problem: https://github.com/Rapporter/pander/issues/309 – daroczig Aug 30 '17 at 11:46

1 Answers1

1

I realised I had forgotten but I had that at some place:

panderOptions('table.alignment.default',
     function(df) ifelse(sapply(df, is.numeric), 'right', 'left'))

Replacing it with:

panderOptions('table.alignment.default',
     function(df) ifelse(sapply(as.data.frame(df), is.numeric), 'right', 'left'))

works fine.

Thanks @daroczig for finding that.

GaryDe
  • 492
  • 1
  • 5
  • 17