check_range: Check that an argument is a numerical range

View source: R/checkmate.R

check_rangeR Documentation

Check that an argument is a numerical range

Description

[Stable]

An argument x is a numerical range if and only if (all conditions must be met):

  1. Is an object of type: integer or double.

  2. Is a vector or length two such that the value of the first number is not less than the second number. Equalness is allowed if and only if unique flag is set to TRUE.

  3. Lower bound of the interval is greater than or equal to lower and upper bound of the interval is less than or equal to upper.

  4. It contains only finite (given that finite is TRUE) and non-missing values.

Usage

check_range(x, lower = -Inf, upper = Inf, finite = FALSE, unique = TRUE)

assert_range(
  x,
  lower = -Inf,
  upper = Inf,
  finite = FALSE,
  unique = TRUE,
  .var.name = checkmate::vname(x),
  add = NULL
)

test_range(x, lower = -Inf, upper = Inf, finite = FALSE, unique = TRUE)

expect_range(
  x,
  lower = -Inf,
  upper = Inf,
  finite = FALSE,
  unique = TRUE,
  info = NULL,
  label = vname(x)
)

Arguments

x

[any]
Object to check.

lower

[numeric(1)]
Lower value all elements of x must be greater than or equal to.

upper

[numeric(1)]
Upper value all elements of x must be lower than or equal to.

finite

[logical(1)]
Check for only finite values? Default is FALSE.

unique

[logical(1)]
Must all values be unique? Default is FALSE.

.var.name

[character(1)]
Name of the checked object to print in assertions. Defaults to the heuristic implemented in vname.

add

[AssertCollection]
Collection to store assertion messages. See AssertCollection.

info

[character(1)]
Extra information to be included in the message for the testthat reporter. See expect_that.

label

[character(1)]
Name of the checked object to print in messages. Defaults to the heuristic implemented in vname.

Value

TRUE if successful, otherwise a string with the error message.

See Also

assertions for more details.

Examples

check_range(c(1, 5))
check_range(c(-5, 1))
check_range(c(4, 1))
check_range(c(1, 1))
check_range(c(1, 1), unique = FALSE)
check_range(1:3)

Roche/crmPack documentation built on April 20, 2024, 1:10 p.m.