Check number of rows
check_nrow.RdCheck if arg is a 2-dimensional object with number of rows equal to or greater/less than or equal to nrow.
Usage
check_nrow_equals(arg, nrow, signal = "error", msg = NULL, call. = FALSE)
check_nrow_leq(arg, nrow, signal = "error", msg = NULL, call. = FALSE)
check_nrow_geq(arg, nrow, signal = "error", msg = NULL, call. = FALSE)Arguments
- arg
(object)
The argument to check.- nrow
(scalar integer)
The number of rows to check.- signal
(string:
c("error", "warning", "message"))
Must be one of"error","warning", or"message"."error"(default) callsbase::stop()to signal an error message."warning"callsbase::warning()to signal a warning message."message"callsbase::message()to signal a message.- msg
(string or
NULL:NULL)
A string that replaces the default message. Set asNULLto use the default message.- call.
(Scalar logical:
c(FALSE, TRUE))
Passed tostop()orwarning(). The defaultmsgincludes it's own formatted call, hencecall.should beFALSE(default). If you insert your ownmsg, then you may wantcall. = TRUE.
See also
Other check_dims:
check_ncol_equals()
Examples
#----------------------------------------------------------------------------
# check_nrow*() examples
#----------------------------------------------------------------------------
library(bkcheck)
#----------------------------------------------------------------------------
# check_nrow_equals()
#----------------------------------------------------------------------------
f <- function(x) {
x |>
check_nrow_equals(1L)
}
f(data.frame(1))
try(f(data.frame(1:2)))
#> Error : Argument `x` must have 1 row.
#>
#> nrow(x) = 2
#>
#> Call: f(x = data.frame(1:2))
#----------------------------------------------------------------------------
# check_nrow_leq()
#----------------------------------------------------------------------------
f <- function(x) {
x |>
check_nrow_leq(2L)
}
f(matrix(1))
try(f(data.frame(1:3, 2:4, 3:5)))
#> Error : Argument `x` must have at most 2 rows.
#>
#> nrow(x) = 3
#>
#> Call: f(x = data.frame(1:3, 2:4, 3:5))
#----------------------------------------------------------------------------
# check_nrow_geq()
#----------------------------------------------------------------------------
f <- function(x) {
x |>
check_data_frame() |>
check_nrow_geq(1L)
}
f(data.frame(1))
try(f(data.frame()))
#> Error : Argument `x` must have at least 1 row.
#>
#> nrow(x) = 0
#>
#> Call: f(x = data.frame())