Skip to content

Commit 6642ddb

Browse files
Print column classes at the bottom if class is enabled (#6905)
* add column class at bottom if row > 20 * correct test number * remove duplicate rbind() call * correctly place bracket * data.table style * remove extra mat_abbs * Restore and add issue number comments
1 parent d28cce9 commit 6642ddb

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
2. `melt()` now supports using `patterns()` with `id.vars`, [#6867](https://github.com/Rdatatable/data.table/issues/6867). Thanks to Toby Dylan Hocking for the suggestion and PR.
1010

11+
3. `print.data.table()` now shows column classes at the bottom of large tables when `class=TRUE` and `col.names="auto"` (default) for tables with more than 20 rows, [#6902](https://github.com/Rdatatable/data.table/issues/6902). This follows the same behavior as column names at the bottom, making it easier to see column types for large tables without scrolling back to the top. Thanks to @TimTaylor for the suggestion and @Mukulyadav2004 for the PR.
12+
1113
## BUG FIXES
1214

1315
1. Custom binary operators from the `lubridate` package now work with objects of class `IDate` as with a `Date` subclass, [#6839](https://github.com/Rdatatable/data.table/issues/6839). Thanks @emallickhossain for the report and @aitap for the fix.

R/print.data.table.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
142142
if (nrow(toprint)>20L && col.names == "auto")
143143
# repeat colnames at the bottom if over 20 rows so you don't have to scroll up to see them
144144
# option to shut this off per request of Oleg Bondar on SO, #1482
145-
toprint = rbind(toprint, matrix(if (quote) old else colnames(toprint), nrow=1L)) # fixes bug #97
145+
toprint = rbind(
146+
toprint,
147+
matrix(if (quote) old else colnames(toprint), nrow=1L), # see #97
148+
if (isTRUE(class)) matrix(abbs, nrow=1L) # #6902
149+
)
146150
print_default(toprint)
147151
invisible(x)
148152
}

inst/tests/tests.Rraw

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21134,3 +21134,10 @@ test(2312, fwrite(DF, nullfile(), encoding = "UTF-8", nThread = 2L), NULL)
2113421134
test(2313,
2113521135
melt(data.table(a=numeric(), b=numeric(), c=numeric()), id.vars=c('a', 'b')),
2113621136
data.table(a=numeric(), b=numeric(), variable=factor(levels='c'), value=numeric()))
21137+
21138+
# Testing column footer display with col.names options in print.data.table #6902
21139+
dt = data.table(id = 1:25)
21140+
# Test with class=TRUE shows classes at bottom with default col.names="auto"
21141+
test(2314.1, any(grepl("<int>", tail(capture.output(print(dt, class = TRUE)), 2))), TRUE)
21142+
# Test that class=TRUE with col.names="top" doesn't show classes at bottom
21143+
test(2314.2, !any(grepl("<int>", tail(capture.output(print(dt, class = TRUE, col.names = "top")), 2))), TRUE)

man/print.data.table.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
\item{x}{ A \code{data.table}. }
4242
\item{topn}{ The number of rows to be printed from the beginning and end of tables with more than \code{nrows} rows. }
4343
\item{nrows}{ The number of rows which will be printed before truncation is enforced. }
44-
\item{class}{ If \code{TRUE}, the resulting output will include above each column its storage class (or a self-evident abbreviation thereof). }
44+
\item{class}{ If \code{TRUE}, the resulting output will include above each column its storage class (or a self-evident abbreviation thereof). When combined with \code{col.names="auto"} and tables >20 rows, classes will also appear at the bottom.}
4545
\item{row.names}{ If \code{TRUE}, row indices will be printed alongside \code{x}. }
46-
\item{col.names}{ One of three flavours for controlling the display of column names in output. \code{"auto"} includes column names above the data, as well as below the table if \code{nrow(x) > 20}. \code{"top"} excludes this lower register when applicable, and \code{"none"} suppresses column names altogether (as well as column classes if \code{class = TRUE}. }
46+
\item{col.names}{ One of three flavours for controlling the display of column names in output. \code{"auto"} includes column names above the data, as well as below the table if \code{nrow(x) > 20} (when \code{class=TRUE}, column classes will also appear at the bottom). \code{"top"} excludes this lower register when applicable, and \code{"none"} suppresses column names altogether (as well as column classes if \code{class = TRUE}. }
4747
\item{print.keys}{ If \code{TRUE}, any \code{\link{key}} and/or \code{\link[=indices]{index}} currently assigned to \code{x} will be printed prior to the preview of the data. }
4848
\item{trunc.cols}{ If \code{TRUE}, only the columns that can be printed in the console without wrapping the columns to new lines will be printed (similar to \code{tibbles}). }
4949
\item{show.indices}{ If \code{TRUE}, indices will be printed as columns alongside \code{x}. }

0 commit comments

Comments
 (0)