Assures that what is returned is an integer within the specified range.
Real values are truncated. A number too large or too small to be an
integer is forced to the maximum or the minimum. Non-numerics are forced to
minimum without warning. Character values that look like numbers are
converted. The limits themselves are not coerced, so non-integer limits can
be returned as given. If minimum is greater than maximum,
maximum wins.
Value
A vector of values forced to be within the specified range. These are integers unless a limit is not an integer.
Examples
library(nprcgenekeepr)
withinIntegerRange()
#> [1] 0
withinIntegerRange(, 0, 10)
#> [1] 0
withinIntegerRange(NA, 0, 10, na = "max")
#> [1] 10
withinIntegerRange(, 0, 10, na = "max") # no argument is not NA
#> [1] 0
withinIntegerRange(LETTERS, 0, 10)
#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
withinIntegerRange(2.6, 1, 5)
#> [1] 2
withinIntegerRange(2.6, 0, 2)
#> [1] 2
withinIntegerRange(c(0, 2.6, -1), 0, 2)
#> [1] 0 2 0
withinIntegerRange(c(0, 2.6, -1, NA), 0, 2)
#> [1] 0 2 0 0
withinIntegerRange(c(0, 2.6, -1, NA), 0, 2, na = "max")
#> [1] 0 2 0 2
withinIntegerRange(c(0, 2.6, -1, NA), 0, 2, na = "min")
#> [1] 0 2 0 0
