Skip to contents

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.

Usage

check_ncols(n, min = 1, max = Inf, allow_null = FALSE)

Arguments

n

The number of columns to check.

min

A numeric value representing the minimum allowed value for n.

max

A numeric value representing the maximum allowed value for n.

allow_null

A logical value indicating whether NULL is allowed as a valid input for n.

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