I believe this might be a bug. If so, I will report. Looking for confirm:
> is.null(data.table(NULL))
[1] FALSE
I see the following in FAQ:
2.5 Is a NULL data.table the same as DT[0]? No, despite the print method indicating otherwise. Strictly speaking it's not possible to have is.null(data.table(NULL)) return FALSE. This FAQ may be revisited in future.
If this is the intended behavior: how does one check if the object is null? In particular, rbindlist
of a NULL object returns a NULL data.table
so how to check?
> is.null(rbindlist(NULL))
[1] FALSE
I'm not sure why the FAQ is phrased the way it is. However, a null data table is just an empty list:
> data.table:::null.data.table
function ()
{
ans = list()
setattr(ans, "class", c("data.table", "data.frame"))
setattr(ans, "row.names", .set_row_names(0L))
settruelength(ans, 0L)
alloc.col(ans)
}
which isn't NULL
. From ?list
:
An empty pairlist, pairlist() is the same as NULL. This is different from list().
You could check for it by seeing whether it is of length 0 (length(DT) == 0
). This is what data.table:::print.data.table
does to decide whether to print "NULL data.table" or "Empty data table (0 rows) ...".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With