Skip to content

setnames for lists? #1948

Description

@MichaelChirico

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...

Activity

  1. mattdowle commented on Dec 2, 2016

    @mattdowle
    Member

    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.

  2. MichaelChirico commented on Dec 2, 2016

    @MichaelChirico
    MemberAuthor
  3. MichaelChirico commented on Jul 8, 2025

    @MichaelChirico
    MemberAuthor

    I don't think this is a real concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions