Skip to content

Commit 3bb4e16

Browse files
Fix index printing by adding index info to header (#6816)
Produce the class header from `toprint` instead of just `x`. Fixes: #6806 Co-authored-by: Ivan K <[email protected]>
1 parent c0469f4 commit 3bb4e16

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

R/print.data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
8686
if (show.indices) toprint = cbind(toprint, index_dt)
8787
}
8888
require_bit64_if_needed(x)
89+
classes = classes1(toprint)
8990
toprint=format.data.table(toprint, na.encode=FALSE, timezone = timezone, ...) # na.encode=FALSE so that NA in character cols print as <NA>
9091

9192
# FR #353 - add row.names = logical argument to print.data.table
@@ -100,7 +101,6 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
100101
factor = "<fctr>", POSIXct = "<POSc>", logical = "<lgcl>",
101102
IDate = "<IDat>", integer64 = "<i64>", raw = "<raw>",
102103
expression = "<expr>", ordered = "<ord>")
103-
classes = classes1(x)
104104
abbs = unname(class_abb[classes])
105105
if ( length(idx <- which(is.na(abbs))) ) abbs[idx] = paste0("<", classes[idx], ">")
106106
toprint = rbind(abbs, toprint)

inst/tests/tests.Rraw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21069,3 +21069,9 @@ if (exists("sort_by", "package:base")) {
2106921069
test(2306.23, DT1[, sort_by(.SD, ~a + b)], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
2107021070
test(2306.24, DT1[, sort_by(.SD, ~.(a, b))], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
2107121071
}
21072+
21073+
DT <- data.table(a = 1:2, b = 2:1)
21074+
setindex(DT, b)
21075+
# make sure that print(DT) doesn't warn due to the header missing index column types, #6806
21076+
# can't use output= here because the print() call is outside withCallingHandlers(...)
21077+
test(2307, { capture.output(print(DT, class = TRUE, show.indices = TRUE)); TRUE })

0 commit comments

Comments
 (0)