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

Possible Enhancement: free and more complex filter in filter-data module #112

Open
lgschuck opened this issue Feb 21, 2025 · 0 comments
Open

Comments

@lgschuck
Copy link

lgschuck commented Feb 21, 2025

First of all congrats on the great work. I'm building my own Shiny package for data analysis and i use many of your packages.

About datamods, even that i'm not using it directly it is a great source of inspiration and learning.

Now, one thing that keep killing me is the possibility for the user to insert a free and complex filter. Something like:

new_df <- mtcars[mtcars$hp == 110 | mtcars$cyl %in% c(4, 6), ] 

In the filter-data module the filters are independent in the tidyverse pipes and so works like a AND stream of filters (as far as i undestand).

I also look into the create-col module and find awesome the extract_calls function and kept thinking of something like that for the filters.

So, after some time i asked GPT for ideias and it suggested me to use the all.names function for a parsed expression. In this way the user could insert a 'free text input' and the validation could be made in the server with a allowed functions list (like in create-cols module).

Of course that parsing the 'free text input' could lead to dangerous situations, but i think that validating the functions in the server could solve the issue.

I dont know if i'm missing something from the all.names function, but reading the help file it seems to me that could be a reasonable choice...

Personnaly i would love if the user could insert a more complex and real life filters...

A simple example:

library(data.table)
df <- setDT(datasets::mtcars)

# parse expression
e1 <- rlang::parse_expr('(hp > 100) & cyl %in% c(4,6)')

operations <- all.names(e1)[all.names(e1) %notin% all.vars(e1)]

allowed_operations <- c('&', '(', '>', '%in%', 'c')

if(all(operations %in% allowed_operations)) filtered_df <- df[eval(e1), ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant