Permalink
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (23 sloc) 532 Bytes
#' Expectation: does a vector have the specified length?
#'
#' @inheritParams expect_that
#' @param n Expected length.
#' @family expectations
#' @export
#' @examples
#' expect_length(1, 1)
#' expect_length(1:10, 10)
#'
#' \dontrun{
#' expect_length(1:10, 1)
#' }
expect_length <- function(object, n) {
stopifnot(is.numeric(n), length(n) == 1)
act <- quasi_label(enquo(object))
act$n <- length(act$val)
expect(
act$n == n,
sprintf("%s has length %i, not length %i.", act$lab, act$n, n)
)
invisible(act$val)
}