正如@MrFlick所指出的那样,quosures赢得了't actually help in this case. You can feasibly use quosures to define column names etc. in a way that would allow you to avoid notes about non-standard evaluation in package functions (I haven' t,但是's on my to-do list for at least one of my packages), but you can'实际上使用了这个策略来使用 . 将值传递给指定的参数或位置 .
3 回答
现在最好的做法是使用quosures . 这个其他SO帖子有一个很好的总结:How to evaluate a constructed string with non-standard evaluation using dplyr?
在实践中,我刚刚将
. = NULL
包含在我的函数顶部 .EDIT
正如@MrFlick所指出的那样,quosures赢得了't actually help in this case. You can feasibly use quosures to define column names etc. in a way that would allow you to avoid notes about non-standard evaluation in package functions (I haven' t,但是's on my to-do list for at least one of my packages), but you can'实际上使用了这个策略来使用
.
将值传递给指定的参数或位置 .值得指出的是,至少有some overhead with using pipes . 可能最佳做法是在包函数中根本不使用管道,这解决了使用
.
的问题 . 对于使用dplyr
命令的NSE的其余部分,您可以使用quosures .似乎最佳做法是使用
.data
而不是.
然后使用rlang
包中的import.data
. 来自programming with dplyr vignette:不幸的是,这对于
dplyr::bind_cols
的原始问题不起作用,但它适用于dplyr::mutate
和dplyr::do
.您发布的代码正在为我运行:
话虽如此,这里有两个产生类似但不同的输出的替代方案:
这里R看到
y
作为x
的前一个参数,因为dplyr::bind_cols
函数期望任意数量的数据帧作为它的第一个参数,因此看到你正在管道它并假设它应该是第一个 .在
.
不起作用的情况下,您也可以将管道变量称为{ . }
. 但是,你可以在这里看到magrittr仍然将y
作为第一个参数,并在我指定{ . }
的地方再次给出它 .因此,我认为magrittr将假设您的管道变量将在第一个可用的机会插入下一个函数,并且您可以再次启动它,或者如果它无法找到该变量的用途
{ . }
.