我只是想了解这里出了什么问题.在第一种情况(工作)中,我将enquo()-ted参数分配给变量,在第二种情况下,我在调用中直接使用了enquoted参数mutate.
library("dplyr")
df <- tibble(x = 1:5, y= 1:5, z = 1:5)
# works
myfun <- function(df, transformation) {
my_transformation <- rlang::enquo(transformation)
df %>%
gather("key","value", x,y,z) %>%
mutate(value = UQ(my_transformation))
}
myfun(df,exp(value))
# does not work
myfun_2 <- function(df, transformation) {
df %>%
gather("key","value", x,y,z) %>%
mutate(value = UQ(rlang::enquo(transformation)))
}
myfun_2(df,exp(value))
#>Error in mutate_impl(.data, dots) : Column `value` is of unsupported type closure
Run Code Online (Sandbox Code Playgroud)
编辑 这里有更多的思路:)
将调用包含到quo()中看起来好像要评估的表达式是"正确构建"的
# looks as if the whole thing should be working …Run Code Online (Sandbox Code Playgroud)