Use string as filter in dplyr?

Is there a way to use a string variable as a filter argument in dplyr? For instance:

filter(iris,Sepal.Length > 6)

will be replaced by

string <- 'Sepal.Length > 6'
filter(iris,string)

Basically, I am looking for the entire filter string as a variable since I am creating the filter string pragmatically. Thanks for any help.

+4
source share
1 answer

If you want to filter with a string argument, you need to use filter_()insteadfilter()

string <- 'Sepal.Length > 6'
filter_(iris, string)

Also note that it is recommended that you use functions when programming *_().

+14
source

Source: https://habr.com/ru/post/1568210/


All Articles