From 67f2a779e52f681d1416b52184054be78a0ad6af Mon Sep 17 00:00:00 2001 From: jangorecki Date: Thu, 3 Sep 2015 00:41:34 +0100 Subject: [PATCH] bugfix for print.data.tasble row.names=FALSE, closes #1307 --- R/data.table.R | 2 +- README.md | 2 ++ inst/tests/tests.Rraw | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/R/data.table.R b/R/data.table.R index d154b3e858..e967a43183 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -136,7 +136,7 @@ print.data.table <- function(x, } toprint=format.data.table(toprint, ...) # FR #5020 - add row.names = logical argument to print.data.table - if (isTRUE(row.names)) rownames(toprint)=paste(format(rn,right=TRUE),":",sep="") else rownames(toprint)=rep.int("", nrow(x)) + if (isTRUE(row.names)) rownames(toprint)=paste(format(rn,right=TRUE),":",sep="") else rownames(toprint)=rep.int("", nrow(toprint)) if (is.null(names(x))) colnames(toprint)=rep("NA", ncol(toprint)) # fixes bug #4934 if (printdots) { toprint = rbind(head(toprint,topn),"---"="",tail(toprint,topn)) diff --git a/README.md b/README.md index d61e4a9f19..59cc2e0409 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,8 @@ 61. `merge.data.table()` didn't set column order (and therefore names) properly in some cases. Fixed now. Closes [#1290](https://github.com/Rdatatable/data.table/issues/1290). Thanks to @ChristK for the minimal example. + 62. data.table's `print` argument `row.names=FALSE` now works for 100+ rows. Closes [#1307](https://github.com/Rdatatable/data.table/issues/1307). Thanks to @jangorecki. + #### NOTES 1. Clearer explanation of what `duplicated()` does (borrowed from base). Thanks to @matthieugomez for pointing out. Closes [#872](https://github.com/Rdatatable/data.table/issues/872). diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index f8e7a47623..64d1f0bea5 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -3562,10 +3562,12 @@ set.seed(45) DT = data.table(x=c("A", "A", "C", "C"), y=1:4, z=runif(4)) test(1137.12, DT[, lapply(.SD, sum), by=x, .SDcols=-"y"], DT[, lapply(.SD, sum), by=x, .SDcols="z"]) -# test for FR #5020 - print.data.table gets new argument "row.names", default=TRUE. if FALSE, the row-names don't get printed +# test for FR #353 / R-Forge #5020 - print.data.table gets new argument "row.names", default=TRUE. if FALSE, the row-names don't get printed # Thanks to Eddi for `capture.output` function! DT <- data.table(x=1:5, y=6:10) -test(1138, capture.output(print(DT, row.names=FALSE)), c(" x y", " 1 6", " 2 7", " 3 8", " 4 9", " 5 10")) +test(1138.1, capture.output(print(DT, row.names=FALSE)), c(" x y", " 1 6", " 2 7", " 3 8", " 4 9", " 5 10")) +DT <- data.table(x=1:101, y=6:106) # bug described in #1307 +test(1138.2, capture.output(print(DT, row.names=FALSE)), c(" x y", " 1 6", " 2 7", " 3 8", " 4 9", " 5 10", "--- ", " 97 102", " 98 103", " 99 104", " 100 105", " 101 106")) # test for FR #2591 (format.data.table issue with column of class "formula") DT <- data.table(x=c(a~b, c~d+e), y=1:2)