[datatable-help] Odd behavior with [.data.table and J

Matthew Dowle mdowle at mdowle.plus.com
Tue Sep 11 15:01:15 CEST 2012


>> For data.table and data.frame interoperability, it would also be useful
>> if setnames worked on data.frames.
>
> Yes, but then there would be a possibility of breaking things.  data.table
> has an .internal.selfref attribute that enables it to be updated by
> reference in a way that allows it to be tracked. If setnames worked for
> data.frame, then I'm not sure we could maintain compatibility. If two
> symbols pointed to the same data.frame, then setnames would update both,
> and that's contrary to traditional R behaviour for example.  When you use
> data.table you know to expect that as you're moving away from traditional
> R behaviour with regard to copies. I suppose we could allow it, and leave
> it up to user to be careful. But is there a reason you can't use
> data.table instead of data.frame?  data.table is() a data.frame as
> data.table inherits from data.frame.

I'll take that back if I may. Since setattr(DF,"names",...) already allows
you to change data.frame names by reference (and any other attribute on
any type) then why not. setnames has some advantages over
setattr(DF,"names",...) such as making sure you pass a names vector of the
correct length, and allowing you to change a column name by name very
easily. I've added FR#2273 "Allow setnames to work on data.frame too" :
https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2273&group_id=240&atid=978
Thanks.

>
>>
>> Thanks,
>>
>>   Christian
>>
>
>




More information about the datatable-help mailing list