tests/testthat/_snaps/case-when.md

conditions inputs can be size zero

Code
  vec_case_when(list(logical()), list(1:2))
Condition
  Error in `vec_case_when()`:
  ! Can't recycle `values[[1]]` (size 2) to size 0.

values are cast to their common type

Code
  vec_case_when(list(FALSE, TRUE), list(1, "x"))
Condition
  Error in `vec_case_when()`:
  ! Can't combine `values[[1]]` <double> and `values[[2]]` <character>.

values must be size 1 or same size as the conditions

Code
  vec_case_when(list(c(TRUE, FALSE, TRUE, TRUE)), list(1:3))
Condition
  Error in `vec_case_when()`:
  ! Can't recycle `values[[1]]` (size 3) to size 4.

default must be size 1 or same size as conditions (exact same as any other values input)

Code
  vec_case_when(list(FALSE), list(1L), default = 2:3)
Condition
  Error in `vec_case_when()`:
  ! Can't recycle `default` (size 2) to size 1.

default_arg can be customized

Code
  vec_case_when(list(FALSE), list(1L), default = 2:3, default_arg = "foo")
Condition
  Error in `vec_case_when()`:
  ! Can't recycle `foo` (size 2) to size 1.
Code
  vec_case_when(list(FALSE), list(1L), default = "x", default_arg = "foo")
Condition
  Error in `vec_case_when()`:
  ! Can't combine <integer> and `foo` <character>.

conditions_arg is validated

Code
  vec_case_when(list("x"), list(1), conditions_arg = 1)
Condition
  Error in `vec_case_when()`:
  ! `arg` must be a string.

values_arg is validated

Code
  vec_case_when(list(TRUE), list(lm(1 ~ 1)), values_arg = 1)
Condition
  Error in `vec_case_when()`:
  ! `arg` must be a string.

default_arg is validated

Code
  vec_case_when(list(TRUE), list(1), default = "x", default_arg = 1)
Condition
  Error in `vec_case_when()`:
  ! `arg` must be a string.

conditions must all be the same size

Code
  vec_case_when(list(c(TRUE, FALSE), TRUE), list(1, 2))
Condition
  Error in `vec_case_when()`:
  ! `conditions[[2]]` must have size 2, not size 1.
Code
  vec_case_when(list(c(TRUE, FALSE), c(TRUE, FALSE, TRUE)), list(1, 2))
Condition
  Error in `vec_case_when()`:
  ! `conditions[[2]]` must have size 2, not size 3.

conditions must be logical (and aren't cast to logical!)

Code
  vec_case_when(list(1), list(2))
Condition
  Error in `vec_case_when()`:
  ! `conditions[[1]]` must be a logical vector, not the number 1.
Code
  vec_case_when(list(TRUE, 3.5), list(2, 4))
Condition
  Error in `vec_case_when()`:
  ! `conditions[[2]]` must be a logical vector, not the number 3.5.
Code
  vec_case_when(list(x), list(1), default = 2)
Condition
  Error in `vec_case_when()`:
  ! `conditions[[1]]` must be a logical vector, not a <my_logical> object.

conditions can't be arrays (#6862)

Code
  vec_case_when(list(x), list(y))
Condition
  Error in `vec_case_when()`:
  ! `conditions[[1]]` must be a logical vector, not a logical matrix.
Code
  vec_case_when(list(x), list(y), size = 3)
Condition
  Error in `vec_case_when()`:
  ! `conditions[[1]]` must be a logical vector, not a logical matrix.
Code
  vec_case_when(list(x), list(y))
Condition
  Error in `vec_case_when()`:
  ! `conditions[[1]]` must be a logical vector, not a logical 1D array.

size overrides the conditions sizes

Code
  vec_case_when(list(TRUE), list(1), size = 5)
Condition
  Error in `vec_case_when()`:
  ! `conditions[[1]]` must have size 5, not size 1.
Code
  vec_case_when(list(c(TRUE, FALSE), c(TRUE, FALSE, TRUE)), list(1, 2), size = 2)
Condition
  Error in `vec_case_when()`:
  ! `conditions[[2]]` must have size 2, not size 3.

ptype overrides the values types

Code
  vec_case_when(list(FALSE, TRUE), list(1, 2), ptype = character())
Condition
  Error in `vec_case_when()`:
  ! Can't convert `values[[2]]` <double> to <character>.

number of conditions and values must be the same

Code
  vec_case_when(list(TRUE), list())
Condition
  Error in `vec_case_when()`:
  ! `conditions` must have size 0, not size 1.
Code
  vec_case_when(list(TRUE, TRUE), list(1))
Condition
  Error in `vec_case_when()`:
  ! `conditions` must have size 1, not size 2.

dots must be empty

Code
  vec_case_when(list(TRUE), list(1), 2)
Condition
  Error in `vec_case_when()`:
  ! `...` must be empty.
  x Problematic argument:
  * ..1 = 2
  i Did you forget to name an argument?

conditions must be a list

Code
  vec_case_when(1, list(2))
Condition
  Error in `vec_case_when()`:
  ! `conditions` must be a list, not the number 1.

values must be a list

Code
  vec_case_when(list(TRUE), 1)
Condition
  Error in `vec_case_when()`:
  ! `values` must be a list, not the number 1.

named inputs show up in the error message

Code
  vec_case_when(list(x = 1.5), list(1))
Condition
  Error in `vec_case_when()`:
  ! `conditions$x` must be a logical vector, not the number 1.5.
Code
  vec_case_when(list(x = 1.5), list(1), conditions_arg = "foo")
Condition
  Error in `vec_case_when()`:
  ! `foo$x` must be a logical vector, not the number 1.5.
Code
  vec_case_when(list(x = 1.5), list(1), conditions_arg = "")
Condition
  Error in `vec_case_when()`:
  ! `x` must be a logical vector, not the number 1.5.
Code
  vec_case_when(list(x = TRUE, y = c(TRUE, FALSE)), list(1, 2))
Condition
  Error in `vec_case_when()`:
  ! `conditions$y` must have size 1, not size 2.
Code
  vec_case_when(list(x = TRUE, y = c(TRUE, FALSE)), list(1, 2), conditions_arg = "foo")
Condition
  Error in `vec_case_when()`:
  ! `foo$y` must have size 1, not size 2.
Code
  vec_case_when(list(x = TRUE, y = c(TRUE, FALSE)), list(1, 2), conditions_arg = "")
Condition
  Error in `vec_case_when()`:
  ! `y` must have size 1, not size 2.
Code
  vec_case_when(list(TRUE, FALSE), list(1, x = "y"))
Condition
  Error in `vec_case_when()`:
  ! Can't combine `values[[1]]` <double> and `values$x` <character>.
Code
  vec_case_when(list(TRUE, FALSE), list(1, x = "y"), values_arg = "foo")
Condition
  Error in `vec_case_when()`:
  ! Can't combine `foo[[1]]` <double> and `foo$x` <character>.
Code
  vec_case_when(list(TRUE, FALSE), list(1, x = "y"), values_arg = "")
Condition
  Error in `vec_case_when()`:
  ! Can't combine `..1` <double> and `x` <character>.
Code
  vec_case_when(list(TRUE), list(NULL))
Condition
  Error in `vec_case_when()`:
  ! `values[[1]]` must be a vector, not `NULL`.
  i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.
Code
  vec_case_when(list(TRUE), list(x = NULL))
Condition
  Error in `vec_case_when()`:
  ! `values$x` must be a vector, not `NULL`.
  i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.
Code
  vec_case_when(list(TRUE), list(NULL), values_arg = "foo")
Condition
  Error in `vec_case_when()`:
  ! `foo[[1]]` must be a vector, not `NULL`.
  i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.
Code
  vec_case_when(list(TRUE), list(x = NULL), values_arg = "foo")
Condition
  Error in `vec_case_when()`:
  ! `foo$x` must be a vector, not `NULL`.
  i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.
Code
  vec_case_when(list(TRUE), list(NULL), values_arg = "")
Condition
  Error in `vec_case_when()`:
  ! `..1` must be a vector, not `NULL`.
  i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.
Code
  vec_case_when(list(TRUE), list(x = NULL), values_arg = "")
Condition
  Error in `vec_case_when()`:
  ! `x` must be a vector, not `NULL`.
  i Read our FAQ about scalar types (`?vctrs::faq_error_scalar_type`) to learn more.

unmatched errors are correct

Code
  vec_case_when(conditions, values, unmatched = "error")
Condition
  Error in `vec_case_when()`:
  ! Each location must be matched.
  x Locations 4, 5, 6, and 7 are unmatched.


Try the vctrs package in your browser

Any scripts or data that you put into this service are public.

vctrs documentation built on Jan. 24, 2026, 1:07 a.m.