Skip to content

Commit

Permalink
fix #314 data.table keys as rownames
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Jul 8, 2018
1 parent 9ea1242 commit 843907d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions R/S3.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ pander.data.table <- function(x, caption = attr(x, 'caption'),
}

requireNamespace('data.table', quietly = TRUE)
if (keys.as.row.names && data.table::haskey(x)) {
row.names.dt <- x[[data.table::key(x)[1]]]
x <- x[, setdiff(colnames(x), data.table::key(x)[1]), with = FALSE]
data.table::setattr(x, 'row.names', row.names.dt)
xx <- copy(x)
if (keys.as.row.names && data.table::haskey(xx)) {
firstkey <- data.table::key(xx)[1]
row.names.dt <- as.character(xx[[firstkey]])
xx <- xx[, setdiff(colnames(xx), firstkey), with = FALSE, drop = FALSE]
data.table::setattr(xx, 'row.names', row.names.dt)
}

pandoc.table(x, caption = caption, ...)
pandoc.table(xx, caption = caption, ...)

}

Expand Down

0 comments on commit 843907d

Please sign in to comment.