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

setorder shouldn't wipe key unnecessarily #3456

Closed
MichaelChirico opened this issue Mar 14, 2019 · 0 comments
Closed

setorder shouldn't wipe key unnecessarily #3456

MichaelChirico opened this issue Mar 14, 2019 · 0 comments
Milestone

Comments

@MichaelChirico
Copy link
Member

@MichaelChirico MichaelChirico commented Mar 14, 2019

DT = data.table(a = rep(4:1, 1:4), v = rnorm(10))
setkey(DT, a)
setorder(DT, a, v)
key(DT)
# NULL

Obviously DT is still sorted by a after setorder; that's why the second setkey here only runs setattr (btw, we should report this is happening if verbose = TRUE)

DT = data.table(a = rep(4:1, 1:4), v = rnorm(10))
setkey(DT, a, v)
setkey(DT, a, verbose = TRUE)

The note in the code is:

if forderv is not 0-length, it means order has changed. So, set key to NULL, else retain key.

So I guess it could be a conceptual question -- do we reset the key if the order has changed but the table is still sorted by the stated key?

This is particularly odd if I want to sort the last column in decreasing order. Is there any have DT keyed by a but guaranteed v is in decreasing order within a?

MichaelChirico pushed a commit that referenced this issue Mar 14, 2019
@mattdowle mattdowle added this to the 1.12.4 milestone Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.