Last data update: 2014.03.03

R: Check if parameter value is valid.
isFeasibleR Documentation

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. If the list is named, it is possible to only pass a subset of parameters defined in the ParamSet par. In that case, only conditions regarding the passed parameters are checked. (Note that this might not work if one of the passed params has a requires setting which refers to an unpassed param.)

Value

logical(1)

Examples

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

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ParamHelpers)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ParamHelpers/isFeasible.Rd_%03d_medium.png", width=480, height=480)
> ### Name: isFeasible
> ### Title: Check if parameter value is valid.
> ### Aliases: isFeasible
> 
> ### ** Examples
> 
> p = makeNumericParam("x", lower = -1, upper = 1)
> isFeasible(p, 0) # True
[1] TRUE
> isFeasible(p, 2) # False, out of bounds
[1] FALSE
> isFeasible(p, "a") # False, wrong type
[1] FALSE
> # now for parameter sets
> ps = makeParamSet(
+   makeNumericParam("x", lower = -1, upper = 1),
+   makeDiscreteParam("y", values = c("a", "b"))
+ )
> isFeasible(ps, list(0, "a")) # True
[1] TRUE
> isFeasible(ps, list("a", 0)) # False, wrong order
[1] FALSE
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>