ivs

Codecov test coverage 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:

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!