【发布时间】:2019-12-25 20:14:25
【问题描述】:
我正在使用 infer 包运行卡方测试,例如,
df %>%
chisq_test(label ~ feature)
我想把它放到一个函数中,这样我就可以写了:
my_chisq_function(df, label, feature)
我通常会通过编写一个类似的函数来做到这一点:
my_chisq_function = function(df, label, feature) {
feature = enquo(feature)
label = enquo(label)
df %>%
chisq_test(!!label ~ !!feature)
}
但是当我运行它时:
my_chisq_function(df, cohort, gender)
我收到一个错误:
Error: The response variable `!` cannot be found in this dataframe.The response variable `!label` cannot be found in this dataframe.
关于如何让它发挥作用的任何想法/建议?
谢谢, D
【问题讨论】:
标签: r lazy-evaluation