tidy-evaluation

Filtering with string statements in dplyr

A question came up recently at work about how to use a filter statement entered as a complete string variable inside dplyr’s filter() function – for example dplyr::filter(my_data, "var1 == 'a'"). There does not seem to be much out there on this and I was not sure how to do it either but luckily jakeybob had a neat solution that seems to work well. some_data %>% filter(eval(rlang::parse_expr(selection_statement))) Let’s see it in action using the iris flowers dataset.