以编程方式将值发送到过滤器的 tidyeval 方法

tidyeval way to programatically send values to filter

接上较早的话题,(Use string as filter in dplyr?), 新的 对此的回答是什么,因为 filter_ 已被弃用。

有没有办法在 中使用字符串变量作为过滤器参数?例如:

filter(iris,Sepal.Length > 6)

将替换为

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

也许:

filter(iris, !! rlang::parse_expr(string))

但据我了解 tidyeval 哲学,代码作为字符串是不受欢迎的,一开始就不应该有 string <- 'Sepal.Length > 6'

也许改为:

condition <- expr(Sepal.Length > 6)
filter(iris, !! condition)