is_bounded: Check whether a value within a certain interval

Description Usage Arguments Examples

View source: R/assertions.R

Description

Check whether a value within a certain interval

Usage

1
2
3
4
5
6
7
is_bounded(
  x,
  lower_bound = -Inf,
  lower_closed = FALSE,
  upper_bound = Inf,
  upper_closed = FALSE
)

Arguments

x

A value to be tested

lower_bound

The lower bound

lower_closed

Whether the lower bound is closed

upper_bound

The upper bound

upper_closed

Whether the upper bound is closed

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Not run: 
library(assertthat)
assert_that(is_bounded(10))
# TRUE

assert_that(is_bounded(10:30))
# TRUE

assert_that(is_bounded(Inf))
# Error: Inf is not bounded by (-Inf,Inf)

assert_that(is_bounded(10, lower_bound = 20))
# Error: 10 is not bounded by (20,Inf)

assert_that(is_bounded(
  10,
  lower_bound = 20,
  lower_closed = TRUE,
  upper_bound = 30,
  upper_closed = FALSE
))
# Error: 10 is not bounded by [20,30)

## End(Not run)

dynutils documentation built on March 22, 2021, 5:06 p.m.