setnames for lists? #1948
Description
Activity
Originally I seem to remember that
setnamesjust worked ondata.table. To restrict todata.tablewhat you could do by reference to avoid unexpected breakage ifset*could reach outsidedata.table's remit.Say a package imports
data.tableand usessetnameson the input it is passed from a user. If that package doesn't remember it should not callsetnameson adata.frameinput, the user using that package could end up with a changed-by-referencedata.frame.But
data.tableusers in their own code really wanted to callsetnamesondata.framesince they wanted to be trusted, keeping thedata.frameas adata.frame, rather than converting to adata.table. So we yielded and crossed our fingers. Relaxing to allow it onlisttoo is one step further.Are we sure we don't have any problems in packages importing
data.table, callingset*ondata.frameinputs? Let alonelistyet.- I don't see anything on SO and I haven't seen anything come up here (also searched closed issues) so I guess it's fine?…On Dec 2, 2016 1:49 AM, "Matt Dowle" ***@***.***> wrote: Originally I seem to remember that setnames just worked on data.table. To restrict to data.table what you could do by reference to avoid unexpected breakage if set* could reach outside data.table's remit. Say a package imports data.table and uses setnames on the input it is passed from a user. If that package doesn't remember it should not call setnames on a data.frame input, the user using that package could end up with a changed-by-reference data.frame. But data.table users in their own code really wanted to call setnames on data.frame since they wanted to be trusted, keeping the data.frame as a data.frame, rather than converting to a data.table. So we yielded and crossed our fingers. Relaxing to allow it on list too is one step further. Are we sure we don't have any problems in packages importing data.table, calling set* on data.frame inputs? Let alone list yet. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#1948 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHQQdZKiQrH188DogbYRVQUpuOEzAHgaks5rD79tgaJpZM4LCJ_4> .
I don't think this is a real concern.
Reacted by Jan Gorecki
Is there a reason usage of
setnamesis restricted todata.tableanddata.frame?Seems inconsistent that
rbindlistcan takelist/data.table/data.frameas input and return the correctdata.tableas output; why notsetnames?This would have the advantage over
setNamesof being done by reference (usually minor for this particular operation) as well as allowing for more consistency in how I usedata.tablefunctions in my code...