check_ncols()
checks if the number of columns (n
)
falls within a specified range, defined by min
and max
.
The function ensures that n
is an integer and meets the specified
conditions. If allow_null
is TRUE
, n
can be
NULL
. Otherwise, an error is raised if n
is not within the
specified bounds.
Value
Returns the number of columns n
if it satisfies the specified
conditions. Otherwise, an error is raised.
Examples
check_ncols(3, min = 1, max = 5)
#> [1] 3
try(check_ncols(10, min = 1, max = 5))
#> Error in check_numeric(num = n, min = min, max = max, is_integer = TRUE, :
#> Expected 'ncols' to be an integer (whole number) between 1 and 5 inclusive but got 10
check_ncols(0, min = 0, max = 5)
#> [1] 0
try(check_ncols(-2, min = 1, max = 5))
#> Error in check_numeric(num = n, min = min, max = max, is_integer = TRUE, :
#> Expected 'ncols' to be an integer (whole number) between 1 and 5 inclusive but got -2