# R/point_in_interval.R In rolandseubert/DHtools: Miscellaneous R Functions for Working with Downhole Data

#### Documented in point_in_interval

```#' Point in Interval
#'
#' This function tests whether or not a point is contained within an interval.
#'
#' The argument \code{closed} takes either a character or a logical vector. The
#' character values can be either \code{"left"} or \code{"right"} to specify
#' whether the interval is left-closed or right-closed. If \code{closed} is
#' specified to be logical it indicates either a closed (\code{TRUE}) or an
#' open (\code{FALSE}) interval.
#'
#' @param p numeric vector containing the value to be compared with the
#' boundaries of the interval.
#' @param i numeric vector of length 2 containing the boundaries of the
#' interval.
#' @param closed character or logical, indicating whether the interval is left-
#' or right-closed, fully closed or open.
#'
#' @return A \code{logical} vector of length 1 specifying whether point
#' \code{p} lies within interval \code{i}.
#'
#' @export
point_in_interval <- function(p, i, closed = "left")
{
if (closed == "left") {
out <- p >= min(i) & p < max(i)
} else if (closed == "right") {
out <- p > min(i) & p <= max(i)
} else if (closed) {
out <- p >= min(i) & p <= max(i)
} else if (!closed) {
out <- p > min(i) & p < max(i)
}

return(out)
}
```
rolandseubert/DHtools documentation built on Aug. 13, 2018, 12:56 a.m.