Skip to content

Commit

Permalink
meld documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Aug 10, 2023
1 parent 18e9c5e commit 1cbd702
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 16 additions & 1 deletion R/sort_linter.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#' Require usage of `sort()` over `.[order(.)]`
#' Check for common mistakes around sorting vectors
#'
#' This linter checks for some common mistakes when using [order()] or [sort()].
#'
#' First, it requires usage of `sort()` over `.[order(.)]`.
#'
#' [sort()] is the dedicated option to sort a list or vector. It is more legible
#' and around twice as fast as `.[order(.)]`, with the gap in performance
#' growing with the vector size.
#'
#' Second, it requires usage of [is.unsorted()] over equivalents using `sort()`.
#'
#' The base function `is.unsorted()` exists to test the sortedness of a vector.
#' Prefer it to inefficient and less-readable equivalents like
#' `x != sort(x)`. The same goes for checking `x == sort(x)` -- use
#' `!is.unsorted(x)` instead.
#'
#' Moreover, use of `x == sort(x)` can be risky because [sort()] drops missing
#' elements by default, meaning `==` might end up trying to compare vectors
#' of differing lengths.
#'
#' @examples
#' # will produce lints
#' lint(
Expand Down
18 changes: 17 additions & 1 deletion man/sort_linter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1cbd702

Please sign in to comment.