iv_span {ivs} | R Documentation |
Span
Description
iv_span()
computes the span of an iv. The span is a single interval which
encompasses the entire range of the iv. It is similar to iv_groups()
, if
groups were also merged across gaps.
iv_span()
is a summary function, like min()
and max()
, so it always
returns a size 1 iv, even for empty ivs. The empty
argument can be used to
control what is returned in the empty case.
Usage
iv_span(x, ..., missing = "propagate", empty = "missing")
Arguments
x |
An interval vector. |
... |
These dots are for future extensions and must be empty. |
missing |
Handling of missing intervals in
|
empty |
Handling of empty
|
Details
iv_span()
is currently limited by the fact that it calls min()
and
max()
internally, which doesn't work for all vector types that ivs
supports (mainly data frames). In the future, we hope to be able to leverage
vctrs::vec_min()
and vctrs::vec_max()
, which don't exist yet.
Examples
x <- iv_pairs(c(1, 5), c(2, 6), c(9, 10))
# The span covers the full range of values seen in `x`
iv_span(x)
# Compare against `iv_groups()`, which merges overlaps but doesn't merge
# across gaps
iv_groups(x)
x <- iv_pairs(c(1, 3), c(NA, NA), c(5, 6), c(NA, NA))
# Because `iv_span()` is a summary function, if any missing intervals are
# present then it returns a missing interval by default
iv_span(x)
# Further control this with `missing`
iv_span(x, missing = "drop")
try(iv_span(x, missing = "error"))
iv_span(x, missing = iv(-1, 0))
x <- iv(double(), double())
# If `x` is empty, then by default a missing interval is returned
iv_span(x)
# Control this with `empty`
try(iv_span(x, empty = "error"))
iv_span(x, empty = iv(-Inf, Inf))
# `empty` kicks in if `missing = "drop"` is used and all elements were
# missing
x <- iv(c(NA, NA), c(NA, NA), ptype = double())
iv_span(x, missing = "drop", empty = iv(-Inf, Inf))