Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Can we make filter_add like filter ? #453

Open
bms63 opened this issue May 31, 2024 · 6 comments
Open

Feature Request: Can we make filter_add like filter ? #453

bms63 opened this issue May 31, 2024 · 6 comments
Labels
enhancement New feature or request programming

Comments

@bms63
Copy link
Collaborator

bms63 commented May 31, 2024

Feature Idea

can we make filter_add like filter ?

Relevant Input

image

Relevant Output

No response

Reproducible Example/Pseudo Code

No response

@bms63 bms63 added enhancement New feature or request programming labels May 31, 2024
@bms63
Copy link
Collaborator Author

bms63 commented May 31, 2024

@ddsjoberg is this one possible for us?

@ddsjoberg
Copy link
Collaborator

We can! We'd just need to capture the input as an quosure, and pass it to dplyr::filter() and rely on it for the error messaging.

We can still supplement the error message with admiral context using a variation on the code below:

testing_filter <- function(data, filter_expr) {
  filter_expr <- rlang::enquo(filter_expr)
  
  tryCatch(
    dplyr::filter(data, !!filter_expr),
    error = \(e) {
      cli::cli_abort(
        c("There was an error in {.arg filter_expr}. See messaging below:",
           x = conditionMessage(e))
      )
    }
  )
}

testing_filter(mtcars, filter_expr = not_a_proper_filter_condition)
#> Error in `value[[3L]]()`:
#> ! There was an error in `filter_expr`. See messaging below:
#> ✖ ℹ In argument: `not_a_proper_filter_condition`. Caused by error: ! object
#>   'not_a_proper_filter_condition' not found

Created on 2024-05-31 with reprex v2.1.0

@bms63
Copy link
Collaborator Author

bms63 commented Jun 3, 2024

@bundfussr @zdz2101 @millerg23 @kaz462 @sadchla-codes phase 2 of error messaging?

@sadchla-codes
Copy link
Collaborator

@bundfussr @zdz2101 @millerg23 @kaz462 @sadchla-codes phase 2 of error messaging?

count me in!

@bundfussr
Copy link
Collaborator

That's definitely something we should improve. We could implement an apply_filter() function (similar to process_set_values_to()) which applies the filter, catches errors, and reissues the error message with references to the arguments/objects the user has specified.

We should also check if we have other cases where we pass user input to dplyr functions and need to catch errors.

@bundfussr
Copy link
Collaborator

I think we can't catch the "unexpected '=' in" error because it is issued when the call is parsed. I.e., the function is not called if it occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request programming
Development

No branches or pull requests

4 participants