I am still trying to understand quosures in R, but I do not understand why the substitution in the function below fails.
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)
It seems like calling my.toggle(rlang::UQS(fn.args))
should be equivalent to my.toggle(toggle = T)
(and, indeed, that's what you get when you wrap the function call in quo
), but the function does not execute correctly. What am I doing wrong?