Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account keep.rownames & key #4468

MichaelChirico opened this issue May 21, 2020 · 3 comments · Fixed by #4469
Closed keep.rownames & key #4468

MichaelChirico opened this issue May 21, 2020 · 3 comments · Fixed by #4469


Copy link

MichaelChirico commented May 21, 2020

This works fine:, keep.rownames = TRUE, key = 'rn')

But it's a bit arcane to know that rn is going to be the rownames' name. More readable might be:, keep.rownames = 'model', key = 'model'

But that's an error:

Error in setkeyv(ans, key) : some columns are not in the data.table: model

Haven't looked yet but it must be setkeyv is applied before the setnames.

Note that this approach already works for setDT:

setDT(DT, keep.rownames = 'model', key = 'model')
Copy link

It might add confusion, but thinking out loud maybe key = TRUE could use the row names as a key by default, or the first column if no row names (the id column will usually be first). This way your first call could be abbreviated to, key = TRUE)

Copy link
Member Author

Hmm but when I read, key=TRUE), actually I think of the answer being setkey(; setkey keys on all columns by default.

Copy link

Right, there could also be special values for key but that might be too much potential confusion to spare a few characters.

@mattdowle mattdowle added this to the 1.14.1 milestone Aug 18, 2021
@jangorecki jangorecki modified the milestones: 1.14.9, 1.15.0 Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

4 participants