Skip to content

Commit fb41736

Browse files
committed
Eliminate early returns
1 parent 0281227 commit fb41736

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

R/expect-shape.R

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ expect_shape = function(object, ..., nrow, ncol, dim) {
5151
dim_object <- base::dim(object)
5252
if (is.null(dim_object)) {
5353
fail(sprintf("Expected %s to have dimensions.", act$lab))
54-
return(invisible(act$val))
55-
}
56-
57-
if (!missing(nrow)) {
54+
} else if (!missing(nrow)) {
5855
check_number_whole(nrow, allow_na = TRUE)
5956
act$nrow <- dim_object[1L]
6057

@@ -71,18 +68,17 @@ expect_shape = function(object, ..., nrow, ncol, dim) {
7168

7269
if (length(dim_object) == 1L) {
7370
fail(sprintf("Expected %s to have two or more dimensions.", act$lab))
74-
return(invisible(act$val))
75-
}
76-
77-
act$ncol <- dim_object[2L]
78-
79-
if (!identical(as.integer(act$ncol), as.integer(ncol))) {
80-
fail(c(
81-
sprintf("Expected %s to have %i columns.", act$lab, ncol),
82-
sprintf("Actual columns: %i.", act$ncol)
83-
))
8471
} else {
85-
pass()
72+
act$ncol <- dim_object[2L]
73+
74+
if (!identical(as.integer(act$ncol), as.integer(ncol))) {
75+
fail(c(
76+
sprintf("Expected %s to have %i columns.", act$lab, ncol),
77+
sprintf("Actual columns: %i.", act$ncol)
78+
))
79+
} else {
80+
pass()
81+
}
8682
}
8783
} else {
8884
# !missing(dim)

0 commit comments

Comments
 (0)