Learn R Programming

ParamHelpers (version 1.3)

isFeasible: Check if parameter value is valid.

Description

Check if a parameter value satisfies the constraints of the parameter description. This includes the requires expressions and the forbidden expression, if par is a ParamSet. If requires is not satisfied, the parameter value must be set to scalar NA to be still feasible, a single scalar even in a case of a vector parameter.

If the parameter has cnames, these are also checked.

Usage

isFeasible(par, x)

Arguments

par
[Param | ParamSet] Parameter or parameter set.
x
[any] Single value to check. For a parameter set this must be a list in the correct order.

Value

  • logical(1)

Examples

Run this code
p = makeNumericParam("x", lower = -1, upper = 1)
isFeasible(p, 0) # True
isFeasible(p, 2) # False, out of bounds
isFeasible(p, "a") # False, wrong type
# now for parameter sets
ps = makeParamSet(
  makeNumericParam("x", lower = -1, upper = 1),
  makeDiscreteParam("y", values = c("a", "b"))
)
isFeasible(ps, list(0, "a")) # True
isFeasible(ps, list("a", 0)) # False, wrong order

Run the code above in your browser using DataLab