Skip to content

Commit

Permalink
Closes #1140. DT[, 0, with=FALSE returns null data.table.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Sep 17, 2015
1 parent 85f7690 commit e7360ef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
ansvals = chmatch(ansvars, names(x))
}
} else if (is.numeric(j)) {
if (all(j == 0L)) return (null.data.table())
if (any(abs(j) > ncol(x) | j==0L)) stop("j out of bounds")
if (any(j<0L) && any(j>0L)) stop("j mixes positive and negative")
if (any(j<0L)) j = seq_len(ncol(x))[j]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@

64. Using `.GRP` unnamed in `j` now returns a variable named `GRP` instead of `.GRP` as the period was causing issues. Same for `.BY`. Closes [#1243](https://github.com/Rdatatable/data.table/issues/1243); thanks to @MichaelChirico for the PR.

65. `DT[, 0, with=FALSE]` returns null data.table to be consistent with `data.frame`'s behaviour. Closes [#1140](https://github.com/Rdatatable/data.table/issues/1140). Thanks to @franknarf1.

#### 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).
Expand Down
8 changes: 6 additions & 2 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -6962,8 +6962,12 @@ dt1<-data.table(X=1:3,X=1:3)
df1<-data.frame(X=1:3,X=1:3,check.names=FALSE)
ls1<-list("X"=1:3,"X"=1:3)
test(1559.1, setDT(dt1, check.names=TRUE), ans)
test(1559.1, setDT(df1, check.names=TRUE), ans)
test(1559.1, setDT(ls1, check.names=TRUE), ans)
test(1559.2, setDT(df1, check.names=TRUE), ans)
test(1559.3, setDT(ls1, check.names=TRUE), ans)

# Fix #1140
test(1560.1, data.table(x=letters[1:5])[, 0, with=FALSE], null.data.table())
test(1560.2, data.table(x=letters[1:5])[, c(0,FALSE), with=FALSE], null.data.table())

##########################

Expand Down

0 comments on commit e7360ef

Please sign in to comment.