Use string as filter in dplyr?
If you want to filter with a string argument, you'll need to use filter_()
instead of filter()
string <- 'Sepal.Length > 6'
filter_(iris, string)
Also note that it's recommended to use the *_()
functions when programming.
This is the only way I have found that works in the new tidyval:
> s = "A<3"
> data.frame(A=1:10, B=1:10) %>% filter(eval(str2expression(s)))
A B
1 1 1
2 2 2
However, I have not figured out how to do this with multiple conditions.