Skip to content

Commit fcd1cab

Browse files
Mukulyadav2004aitap
authored andcommitted
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 599ff52 commit fcd1cab

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21070,6 +21070,12 @@ if (exists("sort_by", "package:base")) {
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
}
2107221072

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 })
21078+
2107321079
# test for enhancing error message of invalid column #6512
2107421080
uniq_diff <- function(...) {
2107521081
.Call("uniq_diff", ...)
@@ -21081,4 +21087,4 @@ capture_error_message <- function(expr) {
2108121087
)
2108221088
msg
2108321089
}
21084-
test(2307, {msg <- capture_error_message(uniq_diff(as.integer(c(1, 2, -1, 4)), 4, FALSE))print(msg)return(grepl("\\[-1\\]", msg))}, TRUE)
21090+
test(2307, {msg <- capture_error_message(uniq_diff(as.integer(c(1, 2, -1, 4)), 4, FALSE))print(msg)return(grepl("\\[-1\\]", msg))}, TRUE)

0 commit comments

Comments
 (0)