Skip to content

Commit a2fcfbe

Browse files
committed
Roll back to single expect_length() implementation
1 parent 9b78015 commit a2fcfbe

File tree

5 files changed

+5
-37
lines changed

5 files changed

+5
-37
lines changed

R/expect-length.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ expect_length <- function(object, n) {
1717
stopifnot(is.numeric(n), length(n) == 1)
1818

1919
act <- quasi_label(enquo(object), arg = "object")
20-
expect_length_impl_(act, n)
21-
}
22-
23-
expect_length_impl_ <- function(act, n) {
2420
act$n <- length(act$val)
2521

2622
if (act$n != n) {

R/expect-shape.R

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,20 @@
77
#' [length()] of a vector.
88
#' @inheritParams expect_that
99
#' @param ... Ignored.
10-
#' @param length Expected [length()] of `object`.
1110
#' @param nrow,ncol Expected [nrow()]/[ncol()] of `object`.
1211
#' @param dim Expected [dim()] of `object`.
1312
#' @family expectations
1413
#' @export
1514
#' @examples
1615
#' x <- matrix(1:9, nrow = 3)
17-
#' expect_shape(x, length = 9)
1816
#' expect_shape(x, nrow = 3)
1917
#' expect_shape(x, ncol = 3)
2018
#' expect_shape(x, dim = c(3, 3))
21-
expect_shape = function(object, ..., length, nrow, ncol, dim) {
19+
expect_shape = function(object, ..., nrow, ncol, dim) {
2220
check_dots_empty()
23-
check_exclusive(length, nrow, ncol, dim)
21+
check_exclusive(nrow, ncol, dim)
2422
act <- quasi_label(enquo(object), arg = "object")
2523

26-
# Re-use expect_length() to ensure they stay in sync.
27-
if (!missing(length)) {
28-
return(expect_length_impl_(act, length))
29-
}
30-
# now that we've handled the length argument, revert to usual base function
31-
length <- base::length
32-
3324
dim_object <- base::dim(object)
3425
if (is.null(dim_object)) {
3526
return(fail(sprintf("%s has no dimensions.", act$lab)))

man/expect_shape.Rd

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/expect-shape.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# length compared correctly
2-
3-
1 has length 1, not length 2.
4-
51
# dim compared correctly
62

73
matrix(nrow = 6, ncol = 3) has dim (6, 3), not (6, 2).
@@ -56,12 +52,12 @@
5652
expect_shape(1:10)
5753
Condition
5854
Error in `expect_shape()`:
59-
! One of `length`, `nrow`, `ncol`, or `dim` must be supplied.
55+
! One of `nrow`, `ncol`, or `dim` must be supplied.
6056
Code
6157
expect_shape(1:10, nrow = 1L, ncol = 2L)
6258
Condition
6359
Error in `expect_shape()`:
64-
! Exactly one of `length`, `nrow`, `ncol`, or `dim` must be supplied.
60+
! Exactly one of `nrow`, `ncol`, or `dim` must be supplied.
6561
x `nrow` and `ncol` were supplied together.
6662
Code
6763
expect_shape(1:10, 2)

tests/testthat/test-expect-shape.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
test_that("length compared correctly", {
2-
expect_success(expect_shape(1, length = 1))
3-
expect_snapshot_failure(expect_shape(1, length = 2))
4-
expect_success(expect_shape(1:10, length = 10))
5-
expect_success(expect_shape(letters[1:5], length = 5))
6-
expect_success(expect_shape(integer(), length = 0))
7-
8-
x <- list(1:10, letters)
9-
out <- expect_shape(x, length = 2)
10-
expect_identical(out, x)
11-
})
12-
131
test_that("dim compared correctly", {
142
expect_success(expect_shape(matrix(nrow = 5, ncol = 4), dim = c(5L, 4L)))
153
expect_snapshot_failure(expect_shape(

0 commit comments

Comments
 (0)