check_xxx_help: Incremental Error Checking

View source: R/check_xxx.R

check_xxx_helpR Documentation

Incremental Error Checking

Description

Conditionally bank error messages in the immediate environment of a function to allow for exhaustive error checking before throwing an exception. Results in a possibly multiple-error, accumulated message to be processed upon completion of error checking.

Usage

check_xxx_help()

check_t(..., .d = " ")

check_tf(...)

check_lgl(..., .na = FALSE, .extras = NULL)

check_nll_or(.funs, ..., .vals = NULL)

check_nas_or(.funs, ..., .vals = NULL)

check_cls(.cls, ...)

check_pop(...)

check_funs(.funs, ..., .vals = NULL)

check_spec(.spec, ..., .na = F)

check_vals(.vals, ..., .a = TRUE, .na = FALSE)

check_chars(.chars, ..., .a = TRUE)

check_dots(.spec, ..., .named = FALSE)

check_when(.whens, .vals, ...)

check_fail(...)

Arguments

...

Differs by function in terms of whether they are named, how many there are, and their property requirements as described in the functions section.

.d

A non-NA character scalar delimiter for collapsing ... into an error message.

.na

A logical scalar indicating whether NA values qualify as 'logical'.

.extras

NULL or a complete atomic object containing additional valid values.

.funs

A complete character vec containing 1 or more property function names.

.vals

A complete atomic object of length length(.whens).

.spec

A complete character scalar containing a property spec.

.a

A logical scalar indicating whether to atomize ... args.

.chars

A complete string object containing

.named

A logical scalar indicating whether ... args must uniquely named without using "".

.whens

A populated atomic object of length length(.vals).

.fun

A character scalar naming the function generating an error or errors.

Value

**A **simpleError object

getterr

A character vector

banked_Errs

All others are called for their side effects.

Functions

  • check_t(): Checks named ... arguments for scalar TRUE-ness. If any named ... argument is not scalar TRUE, collapses unnamed ... args to an error message template, replacing the escape sequence '{@}' with each non-qualifying named ... arg's name.

  • check_tf(): Checks named ... arguments for scalar TRUE-ness or scalar FALSE-ness. If any named ... argument is neither scalar TRUE nor scalar FALSE, banks an error indicating that the argument must be scalar TRUE or scalar FALSE. NOTE: unnamed ... arguments are not valid.

  • check_lgl(): Checks each named ... arg for scalar TRUE-ness, scalar FALSE-ness, scalar NA-ness (if .na is scalar TRUE), or scalar membership in .extras (when .extras is a complete atomic object). Banks an error for each ... that does not qualify. NOTE: unnamed ... arguments are not valid.

  • check_nll_or(): Checks each named ... argument for NULL-ness or for any property describe by any property function named in character argument .funs. Banks an automatically-generated error message for each ... argument that does not qualify. NOTE: Unnamed ... arguments are not valid.

  • check_nas_or(): Checks each named ... argument for scalar NA-ness or for any property describe by any property function named in character argument .funs. Banks an automatically-generated error message for each ... argument that does not qualify. NOTE: Unnamed ... arguments are not valid.

  • check_cls(): Checks each named ... argument for any one the classes named in character argument .cls. Banks an automatically-generated error message for each ... argument that does not qualify. NOTE: Unnamed ... arguments are not valid.

  • check_pop(): Checks each named ... for populated-ness (i.e., non-NULL and not of length 0). Banks an error for each ... argument that does not qualify. NOTE: Unnamed ... arguments are not valid.

  • check_funs(): Checks each named ... argument for a match to any of the property functions named in .funs, and if there is a match and atomic argument .vals is non-NULL, whether the values are all contained in atomic argument .vals. Banks an error for each ... argument that does not qualify. NOTE: Unname ... arguments are not valid.

  • check_spec(): Checks each named ... argument for a match to the property spec in character argument .spec with the additional check for disallowed NA values if logical scalar argument .na = FALSE. Banks an error for each ... argument that does not qualify. NOTE: Unnamed ... arguments are not valid.

  • check_vals(): Checks each named ... argument for atomic-ness and for containing only the atomic values given in .vals. Banks an error for each non-qualifying ... argument. NOTE: Unnamed ... arguments are not valid.

  • check_chars(): Checks each named ... argument (assumed to be of mode 'character') for whether it contains only the characters contained in the character argument .chars. When .a = TRUE, atomizes ... before value checking. Banks an error for each ... argument that does not qualify. NOTE: Unnamed ... arguments are not valid.

  • check_dots(): Checks each ... argument for a match to at least one value of the property spec on character argument .spec. Optionally checks whether all ... arguments are named (when .named = TRUE). Banks an error for missing ... argument names (if there are an missing names and .named = TRUE). Also banks an error for any non-qualifying ... argument. for whether it contains only the characters contained in the character argument .chars. When .a = TRUE, atomizes ... before value checking. Banks an error for each ... argument that does not qualify.

  • check_when(): Assumes two named, atomic, scalar ... arguments. Checks that the value of the second named ... argument is appropriate given the value of the first ... argument by identifying which element of .whens is equal to the value of the first ... argument, and checking the corresponding element of .vals against the second ... argument. Banks an error if the value of the first and the value of the second ... arguments do not pass the check. NOTE: There must be only two named ... arguments and unnamed ... arguments are not valid.

  • check_fail(): Checks each named ... argument for validity (i.e., evaluating an argument does not produce an error). Banks an error for each ... argument that does not qualify. NOTE: Unnamed ... arguments are not valid.

See Also

Other Errs: stopperr()

Examples

egStopper <- function() {stopperr('stopper demo')}
egErrs    <- function() {Errs('Errs demo1', 'Errs demo2')}
egErr     <- function() {err('err', 'demo')}
egErrors  <- function(..., tf = NA, lgl = 42, not = FALSE, pop = NULL,
                           fail = simpleError('error'), funs = 2:4, spec = 42,
                           vals = 42, class = 42, nas.or = NULL, nll.or = NA,
                           chars = '5', when.a = "error.a", when.b = "error.b") {
  bankerr(...elt(1))
  bankErrs(...elt(2), ...elt(3))
  check_tf(tf = tf)
  check_lgl(lgl = lgl)
  check_t(not = not)
  check_pop(pop = pop)
  check_fail(fail = fail)
  check_funs(c('cmp_ch1_vec', 'cmp_ngw_vec'), funs = funs)
  check_spec('cmp_ch1_vec|nll|nas', spec = spec)
  check_vals(letters, vals = vals)
  check_cls('data.frame', class)
  check_nas_or(c('cmp_ch1_vec', 'cmp_ngw_vec'), nas.or = nas.or)
  check_nll_or(c('cmp_ch1_vec', 'cmp_ngw_vec'), nll.or = nll.or)
  check_chars(letters, chars = chars)
  check_when(when.a = when.a, when.b = when.b, c('error.a', ''), c('error.b', ''))
  checkerr()
}
## Not run: 
  egstopperr()
  getterr()
  purgerr()
  getter()
  egErrs()
  egErrs()
  egErrors()

## End(Not run)

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.