@@ -311,29 +311,39 @@ data_filter.grouped_df <- function(x, ...) {
311
311
tmp <- gsub(" >=" , " " , tmp , fixed = TRUE )
312
312
tmp <- gsub(" !=" , " " , tmp , fixed = TRUE )
313
313
314
- # Give more informative message to users
315
- # about possible misspelled comparisons / logical conditions
316
- # check if "=" instead of "==" was used?
317
- if (any(grepl(" =" , tmp , fixed = TRUE ))) {
318
- insight :: format_error(
319
- " Filtering did not work. Please check if you need `==` (instead of `=`) for comparison."
320
- )
321
- }
322
- # check if "&&" etc instead of "&" was used?
323
- logical_operator <- NULL
324
- if (any(grepl(" &&" , .fcondition , fixed = TRUE ))) {
325
- logical_operator <- " &&"
326
- }
327
- if (any(grepl(" ||" , .fcondition , fixed = TRUE ))) {
328
- logical_operator <- " ||"
329
- }
330
- if (! is.null(logical_operator )) {
331
- insight :: format_error(
332
- paste0(
333
- " Filtering did not work. Please check if you need `" ,
334
- substr(logical_operator , 0 , 1 ),
335
- " ` (instead of `" , logical_operator , " `) as logical operator."
314
+ # We want to check whether user used a "=" in the filter syntax. This
315
+ # typically indicates that the comparison "==" is probably wrong by using
316
+ # a "=" instead of `"=="`. However, if a function was provided, we indeed
317
+ # may have "=", e.g. if the pattern was
318
+ # `data_filter(out, grep("pattern", x = value))`. We thus first check if we
319
+ # can identify a function call, and only continue checking for wrong syntax
320
+ # when we have not identified a function.
321
+
322
+ if (! is.function(try(get(gsub(" ^(.*?)\\ ((.*)" , " \\ 1" , tmp )), silent = TRUE ))) {
323
+ # Give more informative message to users
324
+ # about possible misspelled comparisons / logical conditions
325
+ # check if "=" instead of "==" was used?
326
+ if (any(grepl(" =" , tmp , fixed = TRUE ))) {
327
+ insight :: format_error(
328
+ " Filtering did not work. Please check if you need `==` (instead of `=`) for comparison."
336
329
)
337
- )
330
+ }
331
+ # check if "&&" etc instead of "&" was used?
332
+ logical_operator <- NULL
333
+ if (any(grepl(" &&" , .fcondition , fixed = TRUE ))) {
334
+ logical_operator <- " &&"
335
+ }
336
+ if (any(grepl(" ||" , .fcondition , fixed = TRUE ))) {
337
+ logical_operator <- " ||"
338
+ }
339
+ if (! is.null(logical_operator )) {
340
+ insight :: format_error(
341
+ paste0(
342
+ " Filtering did not work. Please check if you need `" ,
343
+ substr(logical_operator , 0 , 1 ),
344
+ " ` (instead of `" , logical_operator , " `) as logical operator."
345
+ )
346
+ )
347
+ }
338
348
}
339
349
}
0 commit comments