[datatable-help] rbindlist(x) doesn't behave like rbind for all null lists
Eduard Antonyan
eduard.antonyan at gmail.com
Tue Oct 29 20:26:42 CET 2013
data.frame does the same thing:
> rbind.data.frame(NULL, NULL)
data frame with 0 columns and 0 rows
> data.frame(NULL)
data frame with 0 columns and 0 rows
rbind(NULL, NULL) is just a different beast.
A part of me want to have an is.null generic function, but then it's not
clear how you'd check for NULL.
On Tue, Oct 29, 2013 at 2:17 PM, caneff at gmail.com <caneff at gmail.com> wrote:
> Yes I can. I suppose the actual inconsistency lies in rbind.data.frame
> then. It doesn't follow the same guarantee of "always outputs a
> data.table". Otherwise
>
> rbind(NULL, NULL)
>
> and
>
> data.frame(NULL)
>
> would have the same result.
>
>
> Maybe I would wonder if calling it a "null data.table" is the right
> terminology, since it really is just an empty data.table. A null
> data.table would imply that is.null would be true.
>
> On Tue Oct 29 2013 at 2:11:30 PM, Eduard Antonyan <
> eduard.antonyan at gmail.com> wrote:
>
>> perhaps you can use length() == 0 instead of is.null() for your purposes
>>
>>
>> On Tue, Oct 29, 2013 at 1:01 PM, Eduard Antonyan <
>> eduard.antonyan at gmail.com> wrote:
>>
>> This is by design, and is not a bug.
>>
>> If you try
>>
>> data.table:::.rbind.data.table(NULL, NULL)
>>
>> in version 1.8.10 you will also get a 0-size data.table in agreement with
>> rbindlist (if you try the above in the very latest version, you will get an
>> error, and I may change that to be same as 1.8.10 - but it doesn't matter
>> much, as you can't get there unless you use ":::", and then all bets are
>> off anyway). Both are supposed to always return data.tables.
>>
>> The reason you're getting something else with rbind(NULL, NULL) is
>> because those NULL's are not data.tables, so a *different* rbind is called,
>> which has nothing to do with data.table.
>>
>>
>>
>> On Tue, Oct 29, 2013 at 12:47 PM, Chris Neff <caneff at gmail.com> wrote:
>>
>> Simple thing:
>>
>> dt <- rbindlist(list(NULL, NULL)) #dt is a data.table with 0 rows and
>> columns
>>
>> is.null(dt) # Prints false
>>
>> d <- rbind(NULL, NULL) #d is NULL
>>
>> is.null(d) # Prints true
>>
>>
>> I would expect the two to be equivalent. This bit me when I was relying
>> on !is.null(dt) before assigning other columns in the data.table.
>> rbindlist should return NULL in this case I would think.
>>
>> Is this working as intended? Or should I file a bug?
>>
>> _______________________________________________
>> datatable-help mailing list
>> datatable-help at lists.r-forge.r-project.org
>>
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20131029/ecdddc1d/attachment-0001.html>
More information about the datatable-help
mailing list