【发布时间】:2017-10-18 14:59:57
【问题描述】:
我仍在尝试理解 R 中的 quosures,但我不明白为什么下面函数中的替换会失败。
my.toggle <- function(toggle) {
if (toggle) {
print("yes")
} else {
print("no")
}
}
fn.args <- list(toggle = T)
my.toggle(rlang::UQS(fn.args)) # fails
# Error in if (toggle) { : argument is not interpretable as logical
rlang::quo(my.toggle(rlang::UQS(fn.args))) # but this is the right function call
# <quosure: global>
# ~my.toggle(toggle = TRUE)
似乎调用my.toggle(rlang::UQS(fn.args)) 应该等效于my.toggle(toggle = T)(事实上,这就是您将函数调用包装在quo 中时得到的结果),但该函数无法正确执行。我做错了什么?
【问题讨论】: