Skip to content

Commit cbfdfb9

Browse files
committed
Provide some extra advice for users of across()-in-filter()
1 parent 52e61e6 commit cbfdfb9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

R/filter.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,22 @@ filter_bullets <- function(cnd, ...) {
247247
index <- cnd$dplyr_error_data$index
248248
result <- cnd$dplyr_error_data$result
249249

250-
glue(
250+
bullets <- cli::format_inline(
251251
"`..{index}` must be a logical vector, not {obj_type_friendly(result)}."
252252
)
253+
254+
if (is.data.frame(result)) {
255+
# Provide some extra advice for people who try and use `across()` inside
256+
# of `filter()`
257+
bullets <- c(
258+
bullets,
259+
i = cli::format_inline(
260+
"If you used {.fn across} to generate this data frame, please use {.fn if_any} or {.fn if_all} instead."
261+
)
262+
)
263+
}
264+
265+
bullets
253266
}
254267

255268
#' @export

tests/testthat/_snaps/filter.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
i In argument: `across(everything(), ~.x > 0)`.
160160
Caused by error:
161161
! `..1` must be a logical vector, not a <tbl_df/tbl/data.frame> object.
162+
i If you used `across()` to generate this data frame, please use `if_any()` or `if_all()` instead.
162163

163164
---
164165

@@ -170,6 +171,7 @@
170171
i In group 1: `x = 1`.
171172
Caused by error:
172173
! `..1` must be a logical vector, not a <tbl_df/tbl/data.frame> object.
174+
i If you used `across()` to generate this data frame, please use `if_any()` or `if_all()` instead.
173175

174176
---
175177

@@ -181,6 +183,7 @@
181183
i In row 1.
182184
Caused by error:
183185
! `..1` must be a logical vector, not a <tbl_df/tbl/data.frame> object.
186+
i If you used `across()` to generate this data frame, please use `if_any()` or `if_all()` instead.
184187

185188
---
186189

@@ -191,6 +194,7 @@
191194
i In argument: `tibble(x > 0, y > 0)`.
192195
Caused by error:
193196
! `..1` must be a logical vector, not a <tbl_df/tbl/data.frame> object.
197+
i If you used `across()` to generate this data frame, please use `if_any()` or `if_all()` instead.
194198

195199
---
196200

@@ -202,6 +206,7 @@
202206
i In group 1: `x = 1`.
203207
Caused by error:
204208
! `..1` must be a logical vector, not a <tbl_df/tbl/data.frame> object.
209+
i If you used `across()` to generate this data frame, please use `if_any()` or `if_all()` instead.
205210

206211
---
207212

@@ -213,6 +218,7 @@
213218
i In row 1.
214219
Caused by error:
215220
! `..1` must be a logical vector, not a <tbl_df/tbl/data.frame> object.
221+
i If you used `across()` to generate this data frame, please use `if_any()` or `if_all()` instead.
216222

217223
# `filter()` doesn't allow data frames with missing or empty names (#6758)
218224

0 commit comments

Comments
 (0)