Helpers for argument validation

The match_arg() function

match_arg(
  arg = "lo",
  choices = c("loooong", "else"),
  several.ok = FALSE,
  none.ok = FALSE
)
#> [1] "loooong"

The check_covariance_matrix() function

check_covariance_matrix(
  matrix(c(1, 2, 2, 1), nrow = 2) * -1
)
#> [1] "Must have positive eigenvalues only"

The check_correlation_matrix() function

check_correlation_matrix(
  matrix(c(1, 0, 0, 0), nrow = 2)
)
#> [1] "Must have ones on the diagonal"

The check_transition_probability_matrix() function

check_correlation_matrix(
  matrix(c(1, 1, 0, 1), nrow = 2)
)
#> [1] "Must be symmetric"

The check_probability_vector() function

check_probability_vector(
  1:5 / sum(1:5),
  len = 4
)
#> [1] "Must have length 4, but has length 5"