You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a reason usage of setnames is restricted to data.table and data.frame?
Seems inconsistent that rbindlist can take list/data.table/data.frame as input and return the correct data.table as output; why not setnames?
This would have the advantage over setNames of being done by reference (usually minor for this particular operation) as well as allowing for more consistency in how I use data.table functions in my code...
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.
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>
.
Activity
mattdowle commentedon Dec 2, 2016
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.MichaelChirico commentedon Dec 2, 2016
MichaelChirico commentedon Jul 8, 2025
I don't think this is a real concern.