MyNixOS website logo
Description

Interval Vectors.

Provides a library for generic interval manipulations using a new interval vector class. Capabilities include: locating various kinds of relationships between two interval vectors, merging overlaps within a single interval vector, splitting an interval vector on its overlapping endpoints, and applying set theoretical operations on interval vectors. Many of the operations in this package were inspired by James Allen's interval algebra, Allen (1983) <doi:10.1145/182.358434>.

ivs

Codecov testcoverage R-CMD-check

ivs (said, “eye-vees”) is a package dedicated to working with intervals in a generic way. It introduces a new type, the interval vector, which is generally referred to as an iv. An iv is created from two parallel vectors representing the starts (inclusive) and ends (exclusive) of the intervals, like this:

library(ivs)

# Interval vector of integers
iv(1:5, 7:11)
#> <iv<integer>[5]>
#> [1] [1, 7)  [2, 8)  [3, 9)  [4, 10) [5, 11)

# Interval vector of dates
starts <- as.Date("2019-01-01") + 0:2
ends <- starts + c(2, 5, 10)

iv(starts, ends)
#> <iv<date>[3]>
#> [1] [2019-01-01, 2019-01-03) [2019-01-02, 2019-01-07) [2019-01-03, 2019-01-13)

There are a number of useful things you can do with these, including:

  • Determining how two ivs are related (i.e. does one precede, follow, or overlap the other?) with iv_locate_overlaps().

  • Grouping / Merging overlapping intervals within a single iv with iv_groups().

  • Splitting an iv on its overlapping endpoints with iv_splits().

  • Applying set theoretical operations on two ivs, such as iv_set_intersect().

Interval vectors are completely generic, meaning that you can create them from any comparable type that is supported by vctrs. This means that user defined S3 types work automatically, like hms::hms(), bit64::integer64(), and clock::year_month_day().

Learning

The best way to learn about ivs is by reading the Getting Started vignette!

Installation

Install the released version from CRAN with:

install.packages("ivs")

You can install the development version of ivs from GitHub with:

# install.packages("pak")
pak::pak("DavisVaughan/ivs")

Inspiration

This package was inspired by many sources!

  • IRanges is the closest equivalent, and inspired many of the function names seen here. It is mainly focused on integer intervals, and always uses closed intervals. It is also based on S4, and unfortunately that currently means it can’t be used as a column in a tibble with the current limitations in vctrs.

  • intervals is another R package that supports intervals. It supports integer/numeric intervals and allows for varying the endpoint bounds.

  • data.table contains a function named foverlaps() for detecting overlaps (which was inspired by IRanges::findOverlaps()).

  • Maintaining Knowledge about Temporal Intervals is a paper by James Allen that iv_locate_relates() is based on. It is a great primer on interval algebra.

  • Why numbering should start at 0 is a small white paper that describes why right-open intervals are often the best choice.

Metadata

Version

0.2.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