key_at: Key at a Position

View source: R/50-ordered_sequence-ops.R

key_atR Documentation

Key at a Position

Description

Returns the key of the element at a one-based position, without removing it. This is the positional companion to peek_at() (which returns the value at a position) and the general form of min_key() (key_at(x, 1)) and max_key() (key_at(x, length(x))).

Usage

key_at(x, index)

Arguments

x

An ordered_sequence.

index

One-based position to read.

Details

Positive integer indices beyond length(x) return NULL. Invalid indices (NA, non-integer, ⁠<= 0⁠, or length not equal to 1) error. Pair with peek_at() to read the value at the same position, or use pop_at() when you also want the remaining sequence.

Value

The key at index, or NULL when index is out of bounds.

See Also

peek_at(), min_key(), max_key(), nearest_key(), lower_bound(), pop_at()

Examples

x <- ordered_sequence("a", "b", "c", keys = c(10, 20, 30))
key_at(x, 2)
key_at(x, 10)

Immutables documentation built on Sept. 26, 2026, 1:07 a.m.