R/ensureRangeOpen.R

Defines functions ensureRangeOpen

Documented in ensureRangeOpen

#' @title ensureRangeOpen
#' @description Ensure that value belongs to the open interval ]a,b[
#' @param x value
#' @param a lower limit
#' @param b upper limit
#' @return corrected value
#' @examples
#' # return 1:
#' ensureRangeOpen(x = 10, a = 0, b = 1)
#' # return 0:
#' ensureRangeOpen(x = 0, a = 0, b = 1)
#' # return 0.5:
#' ensureRangeOpen(x = 0.5, a = 0, b = 1)
#' @export
#'
ensureRangeOpen <- function(x, a, b) {
  if (x < a) {
    return(a)
  } else {
    if (x > b) {
      return(b)
    } else {
      return(x)
    }
  }
}

Try the babsim.hospital package in your browser

Any scripts or data that you put into this service are public.

babsim.hospital documentation built on May 30, 2022, 9:05 a.m.