Skip to content

Incomplete dox in ?setorder #1920

Description

@MichaelChirico

In ?setorder::Usage, we have:

# optimised to use data.table's internal fast order
# x[order(., na.last=TRUE)]

But x[order(., decreasing = TRUE)] is also optimized. Using the example from ?setorder:

set.seed(45L)
DT = data.table(A=sample(3, 10, TRUE), 
         B=sample(letters[1:3], 10, TRUE), C=sample(10))
DT[order(C, decreasing = TRUE), verbose = TRUE]
# order optimisation is on, i changed from 'order(...)' to 'forder(DT, ...)'.
#     A B  C
#  1: 1 b 10
#  2: 2 a  9
#  3: 2 b  8
#  4: 1 a  7
#  5: 2 b  6
#  6: 1 a  5
#  7: 1 c  4
#  8: 1 c  3
#  9: 2 b  2
# 10: 1 b  1

So I guess the documentation should mention this.

Activity

  1. added this to the 1.12.9 milestone on Apr 5, 2020
  2. self-assigned this
    on May 18, 2020
  3. modified the milestones: 1.13.1, 1.13.3 on Oct 17, 2020
  4. modified the milestones: 1.14.3, on Jul 19, 2022
  5. modified the milestones: , 1.15.1 on Oct 29, 2023
  6. MichaelChirico commented on Mar 29, 2024

    @MichaelChirico
    MemberAuthor

    hey @Anirban166, given #6018 I thought this might be a similar PR you could help with, feel free to re-assign :)

  7. Anirban166 commented on Mar 29, 2024

    @Anirban166
    Member

    Thanks for sharing Michael, I'm wondering though if it is as simple as mentioning the forder-applicable case for a descending sort operation in that block of comments:

    # optimised to use data.table's internal fast order
    # x[order(., na.last = TRUE)]
    # x[order(., decreasing = TRUE)]
    

    or did you want me to add more to setorder.Rd such as writing on the performance gains of base R's order vs forder, or investigate for notes on better speedups?

    (I'm not sure what more to add apart from including the case with the decreasing = TRUE argument, especially since for the na.last = TRUE argument too there isn't a section explaining more about the optimized order operation for placing all ordered non-NA values before NAs in the sorted data)

  8. MichaelChirico commented on Mar 30, 2024

    @MichaelChirico
    MemberAuthor

    Yes, I think the simple change is enough.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions