Skip to contents

checking whether a single value in config have correct data type, length and value range

Usage

checkTypeLengthValue(
  config,
  name,
  expect_type,
  expect_len = NULL,
  expect_range = c("equal", "larger", "smaller", "within"),
  expect_value = NULL
)

Arguments

config

the list storing config

name

parameter name in config list

expect_type

expected data type for vector, e.g. c("numeric","integer") for integer values, "character", "logical", etc

expect_len

expected length, NULL for any length

expect_range

expect value range; use "larger","smaller", "equal", "within" for numeric values, but use only "within" for character

expect_value

a single numeric value or a character vector that would be used to check against with expect_range, NULL for any value

Value

a message if config[name] does not satisfy the criteria

Examples

config <- list(pos_Integer = 1, neg_value = -0.2, flag = TRUE,
               length2character = c("a","b"))
# check if positive integer of any length
FastReseg:::checkTypeLengthValue(config, "pos_Integer",
                                 expect_type = c("numeric","integer"),
                                 expect_range = "larger", expect_value = 0)
#> character(0)
# check if negative value of any length
FastReseg:::checkTypeLengthValue(config, "neg_value",
                                 expect_type = "numeric",
                                 expect_range = "smaller", expect_value = 0)
#> character(0)
# check if logical value
FastReseg:::checkTypeLengthValue(config, "flag", expect_type = "logical")
#> character(0)
# check if character has 2 elements within c("a","b")
FastReseg:::checkTypeLengthValue(config, "length2character",
                                 expect_type = "character", expect_len = 2,
                                 expect_range = "within", expect_value = c("a","b"))
#> character(0)