I would like to filter a dataframe df
based on some filter_phrase
using quasiquotation (similar to this question here). However, instead of dynamically setting the column, I would like to evaluate the entire condition:
library(dplyr)
library(rlang)
df <- data.frame(a = 1:5, b = letters[1:5])
filter_phrase <- "a < 4"
df %>% filter(sym(filter_phrase))
The expected output should look like this:
> df %>% filter(a < 4)
a b
1 1 a
2 2 b
3 3 c
Any help is greatly appreciated.