Skip to content

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

Description

@lgschuck

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), ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions