| 1 |
\name{close_intervals} |
| 2 |
|
| 3 |
\alias{close_intervals} |
| 4 |
\alias{close_intervals,Intervals_virtual-method} |
| 5 |
|
| 6 |
\alias{open_intervals} |
| 7 |
\alias{open_intervals,Intervals_virtual-method} |
| 8 |
|
| 9 |
\alias{adjust_closure} |
| 10 |
\alias{adjust_closure,Intervals-method} |
| 11 |
\alias{adjust_closure,Intervals_full-method} |
| 12 |
|
| 13 |
|
| 14 |
\title{Re-represent integer intervals with open or closed endpoints} |
| 15 |
|
| 16 |
\description{ |
| 17 |
Given an integer interval matrix, adjust endpoints so that all |
| 18 |
intervals have the requested closure status. |
| 19 |
} |
| 20 |
|
| 21 |
\usage{ |
| 22 |
\S4method{close_intervals}{Intervals_virtual}(x) |
| 23 |
|
| 24 |
\S4method{open_intervals}{Intervals_virtual}(x) |
| 25 |
|
| 26 |
\S4method{adjust_closure}{Intervals}(x, close_left = TRUE, close_right = TRUE) |
| 27 |
|
| 28 |
\S4method{adjust_closure}{Intervals_full}(x, close_left = TRUE, close_right = TRUE) |
| 29 |
} |
| 30 |
|
| 31 |
\arguments{ |
| 32 |
|
| 33 |
\item{x}{ |
| 34 |
An object of appropriate class, and for which \code{x@type == |
| 35 |
"Z"}. If \code{x@type == "R"}, an error is generated. |
| 36 |
} |
| 37 |
|
| 38 |
\item{close_left}{ |
| 39 |
Should the left endpoints be closed or open? |
| 40 |
} |
| 41 |
|
| 42 |
\item{close_right}{ |
| 43 |
Should the right endpoints be closed or open? |
| 44 |
} |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
\value{ |
| 49 |
An object of the same class as \code{x}, with endpoints adjusted as |
| 50 |
necessary and all \code{closed(x)} set to either \code{TRUE} or |
| 51 |
\code{FALSE}, as appropriate. |
| 52 |
} |
| 53 |
|
| 54 |
\note{ |
| 55 |
The \code{close_intervals} and \code{open_intervals} are for |
| 56 |
convenience, and just call \code{adjust_closure} with the approriate |
| 57 |
arguments. |
| 58 |
|
| 59 |
The \code{x} object may contain empty intervals, with at least one |
| 60 |
open endpoint, and still be valid. (Intervals are invalid if their |
| 61 |
second endpoint is less than their first.) The \code{close_intervals} |
| 62 |
method would, in such cases, create an invalid result; to prevent |
| 63 |
this, empty intervals are detected and removed, with a warning. |
| 64 |
|
| 65 |
This package does not make a distinction between closed and open |
| 66 |
infinite endpoints: an interval with an infinite endpoint extends to |
| 67 |
(plus or minus) infinity regardless of the closure state. For example, |
| 68 |
\code{\link{distance_to_nearest}} will return a \code{0} when |
| 69 |
\code{Inf} is compared to both \code{"[0, Inf)"} and \code{"[0, Inf]"}. |
| 70 |
} |
| 71 |
|
| 72 |
\examples{ |
| 73 |
x <- Intervals( |
| 74 |
c( 1, 5, 10, 1, 6, 20 ), |
| 75 |
closed = c( TRUE, FALSE ), |
| 76 |
type = "Z" |
| 77 |
) |
| 78 |
|
| 79 |
# Empties are dropped |
| 80 |
close_intervals(x) |
| 81 |
adjust_closure(x, FALSE, TRUE) |
| 82 |
|
| 83 |
# Intervals_full |
| 84 |
y <- as( x, "Intervals_full" ) |
| 85 |
closed(y)[1,2] <- TRUE |
| 86 |
open_intervals(y) |
| 87 |
} |