check_probability_range: Check if an argument is a probability range

View source: R/checkmate.R

check_probability_rangeR Documentation

Check if an argument is a probability range

Description

[Stable]

Check if a given numerical interval represents a probability range, that is a sub-interval of (0, 1) interval, that can optionally be closed at any side.

Usage

check_probability_range(x, bounds_closed = TRUE)

assert_probability_range(
  x,
  bounds_closed = TRUE,
  .var.name = checkmate::vname(x),
  add = NULL
)

test_probability_range(x, bounds_closed = TRUE)

expect_probability_range(
  x,
  bounds_closed = TRUE,
  info = NULL,
  label = vname(x)
)

Arguments

x

(number)
an interval to check.

bounds_closed

(logical)
should bounds be closed? This can be a scalar or vector of length two. If it is a scalar, then its value applies equally to lower bound 0 and upper bound 1. If this is a vector with two flags, the first flag corresponds to the lower bound 0 only, and the second to the upper bound 1 only.

.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

x <- c(0, 0.2)
check_probability_range(x)
check_probability_range(rev(x))
check_probability_range(x, bounds_closed = FALSE)
check_probability_range(x, bounds_closed = c(FALSE, TRUE))

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