Skip to content

rowwiseDT() could support setting key #7905

Description

@MichaelChirico

data.table() constructor accepts key= to determine the key() of the resulting table.

I think rowwiseDT() could do the same. Some other considerations:

  • There's some back-compatibility risk if users are already creating tables with columns named key
  • It's no longer possible to create a table with a column named key directly
    • We could in principle allow missing(key) to mean "column named key" and !missing(key) to be the key() setting
  • It could be abused to create really confusing code:
rowwiseDT(
  a = , b = , key = 'a',
  2, 1,
  1, 2
)

rowwiseDT(
  a = , b = ,
  2, key = 'a', 1,
  1, 2
)

rowwiseDT(
  a = , key = 'a', b = ,
  2, 1,
  1, 2
)

I would suggest a linter to discourage that -- key= should either be the first or last argument:

rowwiseDT(key = 'a',
  a = , b = ,
  2, 1,
  1, 2
)

rowwiseDT(
  a = , b = ,
  2, 1,
  1, 2,
   key = 'a'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions