Skip to contents

This function checks if the given options adhere to specified valid options. It validates each option's type, value range, allowed values, and handles NULL and NA values according to the configuration provided in validOptions. It automatically converts numeric options to integers when possible and specified so by validOptions for validation and issues a warning.

Usage

validateIsOption(options, validOptions)

Arguments

options

A list of options to validate.

validOptions

A list specifying the valid configurations for each option in options. Each entry in validOptions should be a list containing the type, allowedValues, valueRange, nullAllowed, and naAllowed parameters for the option it corresponds to.

Value

Does not return a value explicitly. Completes without error if all options are valid according to validOptions. If any validation fails, it stops and generates a descriptive error message, reporting all failures if multiple validations fail.

Details

The function iterates through each option in validOptions, retrieves the corresponding value from options, and validates it using validateVector. The validation covers:

  • Type correctness according to type, with automatic conversion for numeric to integer where appropriate.

  • Whether the value is within the specified valueRange (if applicable).

  • Whether the value is among the allowedValues (if specified).

  • Handling of NULL and NA based on nullAllowed and naAllowed flags.

Examples

options <- list(
  optimizationMethod = "genetic_algorithm",
  includeInteractions = TRUE,
  maxIterations = 1000L,
  convergenceThreshold = 0.02
)

validOptions <- list(
  optimizationMethod = list(
    type = "character", allowedValues = c("gradient_descent", "genetic_algorithm")
  ),
  includeInteractions = list(type = "logical"),
  maxIterations = list(type = "integer", valueRange = c(1L, 10000L)),
  convergenceThreshold = list(type = "numeric", valueRange = c(0, 1))
)

validateIsOption(options, validOptions)
#> NULL