【发布时间】:2019-12-05 06:31:28
【问题描述】:
我有一个想要传递给它的函数。但是,我似乎无法使用 tidy_eval 上下文使其工作。
这是一些数据:
df <- tribble(
~A, ~B,
"hi", "hello",
"bye", "later"
)
我希望能够像这样调用函数:
my_quoting_fn(df, A, str_detect(., pattern = "h*"))
其中第三个参数可以是任何不同的函数。
这是我第一次尝试编写函数:
my_quoting_fn <- function(df, col, func) {
func <- enquo(func)
expr <- quo_get_expr(func)
df %>%
pull({{col}}) %>%
eval(expr)
上面给出了错误:
eval(., expr) 中的错误:'language' 类型的'envir' 参数无效`
如果我尝试:
my_quoting_fn <- function(df, col, func) {
df %>%
pull({{col}}) %>%
{{func}}
我得到了错误
stri_detect_regex(string, pattern, negate = negate, opts_regex = opts(pattern)) 中的错误: 目的 '。'没找到
【问题讨论】:
标签: r dplyr tidyverse rlang tidyeval