MyNixOS website logo
Description

Sort and Order Version Codes.

A lightweight package for sorting version codes in various forms. No strong dependencies guaranteed.

versionsort

CRAN status R-CMD-check Codecov test coverage

versionsort is a lightweight, dependency-free package for sorting version codes. Version codes are considered to be strings of alphanumeric characters split into components by special characters acting as separators; most commonly a dot . or a dash -, but others are allowed as well.

Why use versionsort?

Can't I use base sort function?

Base sort() is not suited to the task of sorting version codes. It sorts strings alphabetically, placing 1.0.10 between 1.0.1 and 1.0.2, for example. ver_sort() places it behind 1.0.9 instead.

What about less known base functions that handle version codes?

There are functions like numeric_version() and compareVersion(). They are, however, much more limited in that they accept only numerical components in version codes. versionsort can handle letters, even if concatenated with numbers, allowing the user to work with version codes like 1.8b0a and 0.3-10vcd1-devel. It correctly detects 8 and 10 in these examples, placing these versions behind codes like 1.8.5 and 0.3-10 respectively.

And what about other R packages?

I'm not aware of any R package providing this functionality. Even if there is any, versionsort is designed to have simple, intuitive API with all functions having the same naming scheme of ver_xxx(), reducing the risk of name clash. Moreover, package developers should appreciate the strict "no dependencies" policy, so that importing versionsort inside their packages won't create indirect dependencies on another five or ten libraries.

Installation

# Install from CRAN: 
install.packages("versionsort")

# Install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("ErdaradunGaztea/versionsort")

How to use versionsort?

versionsort has two main functions, mimicking base R division: vec_order() and vec_sort().

library(versionsort)

version_codes <- c("1.5-0", "1.4-1", "0.0.0.9000", "1.4-0a", "1.4-0")
ver_order(version_codes)
# The two lines below are equivalent (but use the latter for code readability, whenever possible)
version_codes[ver_order(version_codes)]
ver_sort(version_codes)

There are also two functions dedicated to finding the code of the latest/oldest version, aptly named vec_latest() and vec_oldest().

# We can reuse already defined vector of version codes
version_codes <- c("1.5-0", "1.4-1", "0.0.0.9000", "1.4-0a", "1.4-0")
ver_latest(version_codes)
vec_oldest(version_codes)

End notes

I believe in equal rights and treatment for everybody, regardless of their sexuality, gender identity, skin tone, nationality, and other features beyond human control. Thus, I do not allow versionsort to be used in any project that promotes hate based on the aforementioned factors.

Metadata

Version

1.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows