Package 'naturalsort'

Title: Natural Ordering
Description: Provides functions related to human natural ordering. It handles adjacent digits in a character sequence as a number so that natural sort function arranges a character vector by their numbers, not digit characters. It is typically seen when operating systems lists file names. For example, a sequence a-1.png, a-2.png, a-10.png looks naturally ordered because 1 < 2 < 10 and natural sort algorithm arranges so whereas general sort algorithms arrange it into a-1.png, a-10.png, a-2.png owing to their third and fourth characters.
Authors: Kosei Abe
Maintainer: Kosei Abe <[email protected]>
License: BSD_3_clause + file LICENSE
Version: 0.1.3
Built: 2025-03-13 02:44:25 UTC
Source: https://github.com/kos59125/naturalsort

Help Index


Natural Ordering Sort

Description

Provides functions related to natural ordering.


Natural Ordering Factor

Description

naturalfactor creates a factor with levels in natural order.

Usage

naturalfactor(x, levels, ordered = TRUE, ...)

Arguments

x

a character vector.

levels

a character vector whose elements might be appeared in x.

ordered

logical flag that determines whether the factor is ordered.

...

arguments that are passed to factor function.


Natural Ordering Sort

Description

Natural ordering is a kind of alphanumerical ordering. naturalorder returns the order of the argument character #' vector in human natural ascending or descending order. naturalsort returns the sorted vector.

Usage

naturalorder(text, decreasing = FALSE, na.last = TRUE)

naturalsort(text, decreasing = FALSE, na.last = NA)

Arguments

text

a character vector to sort.

decreasing

logical.

na.last

logical. If NA, NAs will be removed of the result.

Value

For naturalorder, the results are indices of vector elements in natural order. For naturalsort, the results are sorted vectors.

Examples

text <- c("a-1.png", "a-2.png", "a-10.png")
print(sort(text))
print(naturalsort(text))