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

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

Closed connorp closed 6 years ago

connorp commented 6 years ago

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.

daroczig commented 6 years ago

Thanks :+1: