assert_integer_scalar: Is an Argument an Integer Scalar?

Description Usage Arguments Value Author(s) Examples

View source: R/assertions.R

Description

Checks if an argument is an integer scalar

Usage

1
assert_integer_scalar(arg, subset = "none", optional = FALSE)

Arguments

arg

A function argument to be checked

subset

A subset of integers that arg should be part of. Should be one of "none" (the default), "positive", "non-negative" or "negative".

optional

Is the checked parameter optional? If set to FALSE and arg is NULL then an error is thrown

Value

The function throws an error if arg is not an integer belonging to the specified subset.

Author(s)

Thomas Neitmann

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
example_fun <- function(num1, num2) {
  assert_integer_scalar(num1, subset = "positive")
  assert_integer_scalar(num2, subset = "negative")
}

example_fun(1, -9)

try(example_fun(1.5, -9))

try(example_fun(2, 0))

try(example_fun("2", 0))

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.