Skip to content

Commit b15f235

Browse files
committed
coloumn width adjusted
1 parent e25ea80 commit b15f235

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

R/print.data.table.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
139139
print_default(toprint)
140140
return(invisible(x))
141141
}
142+
if (col.names == "none")
143+
colnames(toprint) <- rep.int("", ncol(toprint))
142144
if (nrow(toprint)>20L && col.names == "auto")
143145
# repeat colnames at the bottom if over 20 rows so you don't have to scroll up to see them
144146
# option to shut this off per request of Oleg Bondar on SO, #1482
@@ -263,8 +265,8 @@ char.trunc = function(x, trunc.char = getOption("datatable.prettyprint.char")) {
263265
dt_width = function(x, nrow, class, row.names, col.names) {
264266
widths = apply(nchar(x, type='width'), 2L, max)
265267
if (class) widths = pmax(widths, 6L)
266-
if (col.names != "none") names = sapply(colnames(x), nchar, type="width") else names = 0L
267-
dt_widths = pmax(widths, names)
268+
names_widths = if (col.names == "none") rep(0L, ncol(x)) else sapply(colnames(x), nchar, type = "width")
269+
dt_widths = pmax(widths, names_widths)
268270
rownum_width = if (row.names) as.integer(ceiling(log10(nrow))+2.0) else 0L
269271
cumsum(dt_widths + 1L) + rownum_width
270272
}

inst/tests/tests.Rraw

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21141,3 +21141,16 @@ dt = data.table(id = 1:25)
2114121141
test(2314.1, any(grepl("<int>", tail(capture.output(print(dt, class = TRUE)), 2))), TRUE)
2114221142
# Test that class=TRUE with col.names="top" doesn't show classes at bottom
2114321143
test(2314.2, !any(grepl("<int>", tail(capture.output(print(dt, class = TRUE, col.names = "top")), 2))), TRUE)
21144+
21145+
test(2313.1, {
21146+
dt <- data.table(short=1:3, verylongcolumnname=4:6)
21147+
print(dt, col.names="none")
21148+
}, output="1: 1 4\n2: 2 5\n3: 3 6\n")
21149+
test(2313.2, {
21150+
dt <- data.table(x=123456, y="wide_string")
21151+
print(dt, col.names="none")
21152+
}, output="1: 123456 wide_string\n")
21153+
test(2313.3, {
21154+
dt <- data.table(a=NA_integer_, b=NaN)
21155+
print(dt, col.names="none")
21156+
}, output="1: NA NaN\n")

0 commit comments

Comments
 (0)