Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown

Home Page:http://rapporter.github.io/pander/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

data.table factor variable as key throws error in pander.data.table

connorp opened this issue · comments

When using pander to print a data.table, if the first variable on which the table is keyed is a factor variable, pander causes an error to be thrown. The problem is on lines 258 and 260 of S3.R:

row.names.dt <- x[[data.table::key(x)[1]]]

If the first variable is a factor variable, then when you attempt to set the row.names:

data.table::setattr(x, 'row.names', row.names.dt)

An error is thrown:

Error in setattr(test, "row.names", test[[key(test)[1]]]) : 
  row names must be 'character' or 'integer', not 'integer'

Coercing row.names.dt to character before passing it to setattr() should solve the issue.

Thanks 👍