Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tests/testthat/_snaps/dplyr-case-match.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
case_match(1)
Condition
Error in `case_match()`:
! At least one condition must be supplied.
! `...` can't be empty.

---

Code
case_match(1, NULL)
Condition
Error in `case_match()`:
! At least one condition must be supplied.
! `...` can't be empty.

# `.default` is part of common type computation

Code
case_match(1, 1 ~ 1L, .default = "x")
Condition
Error in `case_match()`:
! Can't combine `..1 (right)` <integer> and `.default` <character>.
! Can't combine <integer> and `.default` <character>.

# `NULL` formula element throws meaningful error

Expand All @@ -29,6 +29,7 @@
Condition
Error in `case_match()`:
! `..1 (right)` must be a vector, not `NULL`.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

---

Expand All @@ -37,6 +38,7 @@
Condition
Error in `case_match()`:
! `..1 (left)` must be a vector, not `NULL`.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

# throws chained errors when formula evaluation fails

Expand Down
55 changes: 47 additions & 8 deletions tests/testthat/_snaps/dplyr-case-when.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
case_when(FALSE ~ 1L, .default = 2:5)
Condition
Error in `case_when()`:
! `.default` must have size 1, not size 4.
! Can't recycle `.default` (size 4) to size 1.

# `.default` is part of common type computation

Code
case_when(TRUE ~ 1L, .default = "x")
Condition
Error in `case_when()`:
! Can't combine `..1 (right)` <integer> and `.default` <character>.
! Can't combine <integer> and `.default` <character>.

# passes through `.size` correctly

Expand All @@ -35,8 +35,27 @@
Code
case_when(1 ~ NULL)
Condition
Error in `case_when()`:
! `..1 (right)` must be a vector, not `NULL`.
Warning:
Calling `case_when()` with size 1 LHS inputs and size >1 RHS inputs was deprecated in dplyr 1.2.0.
i This `case_when()` statement can result in subtle silent bugs and is very inefficient.

Please use a series of if statements instead:

```
# Previously
case_when(scalar_lhs1 ~ rhs1, scalar_lhs2 ~ rhs2, .default = default)

# Now
if (scalar_lhs1) {
rhs1
} else if (scalar_lhs2) {
rhs2
} else {
default
}
```
Error in `case_when()`:
! `..1 (left)` must be a logical vector, not an empty numeric vector.

---

Expand Down Expand Up @@ -73,7 +92,7 @@
Output
<error/vctrs_error_incompatible_size>
Error in `case_when()`:
! Can't recycle `..1 (left)` (size 2) to match `..1 (right)` (size 3).
! Can't recycle `..1 (right)` (size 3) to match `..2 (right)` (size 2).
Code
(expect_error(case_when(c(TRUE, FALSE) ~ 1, c(FALSE, TRUE, FALSE) ~ 2, c(FALSE,
TRUE, FALSE, NA) ~ 3)))
Expand All @@ -83,6 +102,26 @@
! Can't recycle `..1 (left)` (size 2) to match `..2 (left)` (size 3).
Code
(expect_error(case_when(50 ~ 1:3)))
Condition
Warning:
Calling `case_when()` with size 1 LHS inputs and size >1 RHS inputs was deprecated in dplyr 1.2.0.
i This `case_when()` statement can result in subtle silent bugs and is very inefficient.

Please use a series of if statements instead:

```
# Previously
case_when(scalar_lhs1 ~ rhs1, scalar_lhs2 ~ rhs2, .default = default)

# Now
if (scalar_lhs1) {
rhs1
} else if (scalar_lhs2) {
rhs2
} else {
default
}
```
Output
<error/rlang_error>
Error in `case_when()`:
Expand All @@ -104,17 +143,17 @@
Output
<error/rlang_error>
Error in `case_when()`:
! At least one condition must be supplied.
! `...` can't be empty.
Code
(expect_error(case_when(NULL)))
Output
<error/rlang_error>
Error in `case_when()`:
! At least one condition must be supplied.
! `...` can't be empty.
Code
(expect_error(case_when(~ 1:2)))
Output
<error/rlang_error>
Error in `case_when()`:
! Case 1 (`~1:2`) must be a two-sided formula.
! Case 1 (`~1:2`) must be a two-sided formula, not a one-sided formula.

3 changes: 2 additions & 1 deletion tests/testthat/_snaps/dplyr-coalesce.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
coalesce(NULL, NULL)
Condition
Error in `coalesce()`:
! `...` can't be empty.
! `...` must contain at least 1 non-`NULL` value.

# inputs must be vectors

Expand All @@ -44,6 +44,7 @@
Condition
Error in `coalesce()`:
! `..2` must be a vector, not an environment.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

# names in error messages are indexed correctly

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/_snaps/dplyr-consecutive-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
Condition
Error in `consecutive_id()`:
! `..1` must be a vector, not a function.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

1 change: 1 addition & 0 deletions tests/testthat/_snaps/dplyr-desc.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
Condition
Error in `desc()`:
! `x` must be a vector, not a function.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

14 changes: 3 additions & 11 deletions tests/testthat/_snaps/dplyr-if-else.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@
if_else(x < 2, bad, x)
Condition
Error in `if_else()`:
! `true` must have size 3, not size 2.
! Can't recycle `true` (size 2) to size 3.

---

Code
if_else(x < 2, x, bad)
Condition
Error in `if_else()`:
! `false` must have size 3, not size 2.
! Can't recycle `false` (size 2) to size 3.

---

Code
if_else(x < 2, x, x, missing = bad)
Condition
Error in `if_else()`:
! `missing` must have size 3, not size 2.
! Can't recycle `missing` (size 2) to size 3.

# must have empty dots

Expand All @@ -66,11 +66,3 @@
! Can't convert from `false` <double> to <integer> due to loss of precision.
* Locations: 1

# `size` overrides the `condition` size

Code
if_else(TRUE, 1, 2, size = 2)
Condition
Error in `if_else()`:
! `condition` must have size 2, not size 1.

2 changes: 2 additions & 0 deletions tests/testthat/_snaps/dplyr-lead-lag.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
Condition
Error in `lead()`:
! `x` must be a vector, not an environment.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

---

Expand All @@ -67,4 +68,5 @@
Condition
Error in `lag()`:
! `x` must be a vector, not an environment.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

1 change: 1 addition & 0 deletions tests/testthat/_snaps/dplyr-n-distinct.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
Condition
Error in `n_distinct()`:
! `..1` must be a vector, not a function.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

2 changes: 2 additions & 0 deletions tests/testthat/_snaps/dplyr-na-if.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Condition
Error in `na_if()`:
! `x` must be a vector, not an environment.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

---

Expand All @@ -46,4 +47,5 @@
Condition
Error in `na_if()`:
! `y` must be a vector, not an environment.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

1 change: 1 addition & 0 deletions tests/testthat/_snaps/dplyr-nth-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
Condition
Error in `vec_size()`:
! `x` must be a vector, not an environment.
i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

# `order_by` must be the same size as `x`

Expand Down