You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dplyr::if_else() fails when condition is a labelled logical vector #6678
Starting with dplyr 1.1.0, dplyr::if_else() fails with a meaningless error message when condition is a labelled logical vector:
d<-mtcars|>dplyr::mutate(mileage=mpg>20) |>labelled::set_variable_labels(mileage="mileage dummy")
dplyr::if_else(d$mileage,
"guzzler",
"moderate")
#> Error in `dplyr::if_else()`:#> ! `condition` must be a vector with type <logical>.#> Instead, it has type <logical>.#> Backtrace:#> ▆#> 1. └─dplyr::if_else(d$mileage, "guzzler", "moderate")#> 2. └─vctrs::vec_assert(x = condition, ptype = logical(), arg = "condition")#> 3. └─rlang::abort(...)
Explicitly providing the correct prototype gives the same result:
dplyr::if_else(d$mileage,
"guzzler",
"moderate",
ptype=vctrs::vec_ptype(d$mileage))
#> Error in `dplyr::if_else()`:#> ! `condition` must be a vector with type <logical>.#> Instead, it has type <logical>.#> Backtrace:#> ▆#> 1. └─dplyr::if_else(d$mileage, "guzzler", "moderate", ptype = vctrs::vec_ptype(d$mileage))#> 2. └─vctrs::vec_assert(x = condition, ptype = logical(), arg = "condition")#> 3. └─rlang::abort(...)
changed the title [-][`dplyr::if_else()`](https://dplyr.tidyverse.org/reference/if_else.html) fails when `condition` is a **labelled** logical vector[/-][+]`dplyr::if_else()` fails when `condition` is a **labelled** logical vector[/+]on Feb 2, 2023
changed the title [-]`dplyr::if_else()` fails when `condition` is a **labelled** logical vector[/-][+]`dplyr::if_else()` fails when `condition` is a labelled logical vector[/+]on Feb 2, 2023
Activity
[-][`dplyr::if_else()`](https://dplyr.tidyverse.org/reference/if_else.html) fails when `condition` is a **labelled** logical vector[/-][+]`dplyr::if_else()` fails when `condition` is a **labelled** logical vector[/+][-]`dplyr::if_else()` fails when `condition` is a **labelled** logical vector[/-][+]`dplyr::if_else()` fails when `condition` is a labelled logical vector[/+]