Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@
#
# remaining 99,987 of these 100,000 were already identical
```

41. `dcast(empty-DT)` now returns an empty `data.table` rather than error `Cannot cast an empty data.table`, [#1215](https://github.com/Rdatatable/data.table/issues/1215). Thanks to Damian Betebenner for reporting, and Matt Dowle for fixing.

## NOTES

Expand Down
1 change: 0 additions & 1 deletion R/fcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ...,
idx = which(eval(subset, data, parent.frame())) # any advantage thro' secondary keys?
dat = .Call(CsubsetDT, dat, idx, seq_along(dat))
}
if (!nrow(dat) || !ncol(dat)) stopf("Can not cast an empty data.table")
fun.call = m[["fun.aggregate"]]
fill.default = NULL
if (is.null(fun.call)) {
Expand Down
3 changes: 1 addition & 2 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -13717,8 +13717,7 @@ test(1962.086, dcast(DT, a ~ a, drop = NA),
DT = data.table(a = c(1, 1, 2, 2), b = list(1, 2, 3, 4), c = c(4, 4, 2, 2))
test(1962.087, dcast(DT, a ~ b, value.var = 'b'),
error = 'Columns specified in formula can not be of type list')
test(1962.088, dcast(DT[0L, ], a ~ c, value.var = 'b'),
error = 'Can not cast an empty data.table')
test(1962.088, dcast(DT[0L, ], a ~ c, value.var = 'b'), data.table(a=numeric(), key="a")) #1215
test(1962.089, dcast(DT, a ~ c, value.var = 'b'),
data.table(a = c(1, 2), `2` = c(0L, 2L), `4` = c(2L, 0L), key = 'a'),
message = 'Aggregate function missing')
Expand Down