Skip to content

Commit df22a1b

Browse files
committed
A few more clarifications
1 parent 5e8f2ef commit df22a1b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

vignettes/custom-expectation.Rmd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ To do this we'll add an extra check that the input is either an atomic vector or
9595
expect_vector_length <- function(object, n) {
9696
act <- quasi_label(rlang::enquo(object))
9797
98-
if (!is.atomic(act$val) && !is.list(act$val)) {
98+
# It's non-trivial to check if an object is a vector in base R so we
99+
# use an rlang helper
100+
if (!rlang::is_vector(act$val)) {
99101
msg <- sprintf("%s is a %s, not a vector", act$lab, typeof(act$val))
100102
return(fail(msg))
101103
}
@@ -160,6 +162,7 @@ x3 <- factor()
160162
expect_s3_class(x1, "integer")
161163
expect_s3_class(x2, "integer")
162164
expect_s3_class(x3, "integer")
165+
expect_s3_class(x3, "factor")
163166
```
164167

165168
Note that I also check that the `class` argument must be a string. This is an error, not a failure, because it suggests you're using the function incorrectly.
@@ -192,4 +195,8 @@ expect_length <- function(object, n) {
192195
}
193196
```
194197

195-
Note that the helper probably shouldn't be user facing, and we give it a `_` suffix to make that clear. It's also typically easiest for a helper to take the labelled value produced by `quasi_label()` rather than having to do that repeatedly.
198+
A few recommendations:
199+
200+
* The helper shouldn't be user facing, so we give it a `_` suffix to make that clear.
201+
* It's typically easiest for a helper to take the labelled value produced by `quasi_label()`.
202+
* Your helper should usually call both `fail()` and `pass()` and be returned from the wrapping expectation.

0 commit comments

Comments
 (0)