as_interval_index: Build an Interval Index from 'x', 'start', and 'end'

View source: R/60-interval_index-constructors.R

as_interval_indexR Documentation

Build an Interval Index from x, start, and end

Description

Constructs an interval_index by pairing each element of x with corresponding start and end endpoints.

Usage

as_interval_index(x, start, end, default_query_bounds = "[)")

Arguments

x

Elements to add.

start

Start endpoints with the same length as x.

end

End endpoints with the same length as x.

default_query_bounds

Boundary convention used as the default for query operations on this index: one of "[)", "[]", "()", "(]". Per-query ⁠peek_*⁠ / ⁠pop_*⁠ calls may override via their own bounds argument.

Details

Output is ordered by interval start.

Names on x are preserved as element names.

Value

An interval_index.

Examples

ix <- as_interval_index(c("a", "b", "c"), start = c(1, 2, 2), end = c(3, 2, 4))
ix
as.list(peek_all_point(ix, 2))

# Endpoints can be other comparable types
ix_date <- as_interval_index(
  c("phase1", "phase2"),
  start = as.Date(c("2024-01-01", "2024-01-10")),
  end = as.Date(c("2024-01-05", "2024-01-15"))
)
ix_date

Immutables documentation built on April 29, 2026, 1:06 a.m.