iv_align()
will align/join needles
and haystack
together using a data
frame of locations
. These locations
are intended to be the output of one
of: iv_locate_overlaps()
, iv_locate_precedes()
, iv_locate_follows()
,
iv_locate_relates()
, or iv_locate_between()
.
This is mainly a convenience function that slices both needles
and
haystack
according to those locations
, and then stores the result
in a new two column data frame.
Arguments
- needles, haystack
[vector]
Two vectors to align.
- ...
These dots are for future extensions and must be empty.
- locations
[two-column data frame]
The data frame of locations returned from one of
iv_locate_overlaps()
,iv_locate_precedes()
,iv_locate_follows()
,iv_locate_relates()
, oriv_locate_between()
.
Value
A two column data frame with a $needles
column containing the
sliced version of needles
and a $haystack
column containing the sliced
version of haystack
.
Examples
needles <- iv_pairs(c(1, 5), c(3, 7), c(10, 12))
haystack <- iv_pairs(c(0, 2), c(4, 6))
locations <- iv_locate_overlaps(needles, haystack)
iv_align(needles, haystack, locations = locations)
#> needles haystack
#> 1 [1, 5) [0, 2)
#> 2 [1, 5) [4, 6)
#> 3 [3, 7) [4, 6)
#> 4 [10, 12) [NA, NA)
locations <- iv_locate_overlaps(needles, haystack, no_match = "drop")
iv_align(needles, haystack, locations = locations)
#> needles haystack
#> 1 [1, 5) [0, 2)
#> 2 [1, 5) [4, 6)
#> 3 [3, 7) [4, 6)
needles <- c(1, 15, 4, 11)
haystack <- iv_pairs(c(1, 5), c(3, 7), c(10, 12))
locations <- iv_locate_between(needles, haystack)
iv_align(needles, haystack, locations = locations)
#> needles haystack
#> 1 1 [1, 5)
#> 2 15 [NA, NA)
#> 3 4 [1, 5)
#> 4 4 [3, 7)
#> 5 11 [10, 12)