diff --git a/R/print.data.table.R b/R/print.data.table.R index 7517a4f128..a37020f502 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -86,6 +86,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), if (show.indices) toprint = cbind(toprint, index_dt) } require_bit64_if_needed(x) + classes = classes1(toprint) toprint=format.data.table(toprint, na.encode=FALSE, timezone = timezone, ...) # na.encode=FALSE so that NA in character cols print as # 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"), factor = "", POSIXct = "", logical = "", IDate = "", integer64 = "", raw = "", expression = "", ordered = "") - classes = classes1(x) abbs = unname(class_abb[classes]) if ( length(idx <- which(is.na(abbs))) ) abbs[idx] = paste0("<", classes[idx], ">") toprint = rbind(abbs, toprint) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index e4231b5fa8..b2ebe2645a 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21069,3 +21069,9 @@ if (exists("sort_by", "package:base")) { 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))) 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))) } + +DT <- data.table(a = 1:2, b = 2:1) +setindex(DT, b) +# make sure that print(DT) doesn't warn due to the header missing index column types, #6806 +# can't use output= here because the print() call is outside withCallingHandlers(...) +test(2307, { capture.output(print(DT, class = TRUE, show.indices = TRUE)); TRUE })