Skip to contents

check_nrows() checks if the number of rows (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_nrows(n, min = 1, max = Inf, allow_null = FALSE)

Arguments

n

The number of rows 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 rows n if it satisfies the specified conditions. Otherwise, an error is raised.

Examples

check_nrows(5, min = 1, max = 10)
#> [1] 5

try(check_nrows(15, min = 1, max = 10))
#> Error in check_numeric(num = n, min = min, max = max, is_integer = TRUE,  : 
#>   Expected 'nrows' to be an integer (whole number) between 1 and 10 inclusive but got 15

check_nrows(0, min = 0, max = 10)
#> [1] 0

try(check_nrows(-3, min = 1, max = 10))
#> Error in check_numeric(num = n, min = min, max = max, is_integer = TRUE,  : 
#>   Expected 'nrows' to be an integer (whole number) between 1 and 10 inclusive but got -3