require(tidyr)
require(dplyr)
require(lazyeval)
df = data.frame(varName=c(1,2))
Run Code Online (Sandbox Code Playgroud)
聚集作品:
df %>% gather(variable,value,varName)
Run Code Online (Sandbox Code Playgroud)
但我希望能够在标准评估模式下从变量中获取名称varName,并且似乎无法正确使用它:
name='varName'
df %>% gather_("variable","value",interp(~v,v=name))
Error in match(x, y, 0L) : 'match' requires vector arguments
Run Code Online (Sandbox Code Playgroud)
我也对以下内容感到困惑.
这按预期工作:
df %>% gather_("variable","value","varName")
Run Code Online (Sandbox Code Playgroud)
下一行应该等同于最后一行(根据我对http://cran.r-project.org/web/packages/dplyr/vignettes/nse.html的理解),但不起作用:
df %>% gather_(~variable,~value,~varName)
Error in match(x, y, 0L) : 'match' requires vector arguments
Run Code Online (Sandbox Code Playgroud)
查看源代码tidyr:::gather_.data.frame,您可以看到它只是一个包装器reshape2::melt.因此,它只适用于character或numeric参数.实际上以下(我会考虑一个错误)工作:
df %>% gather_("variable", "value", 1)
Run Code Online (Sandbox Code Playgroud)
据我所知,nse小插图仅涉及dplyr而不是指tidyr.