r - {rlang }'s ' curly-curly'运算符 `{{`是如何实现的?

标签 r tidyverse metaprogramming rlang nse

help("nse-force") 中的 {rlang} 文档提供以下内容:

The curly-curly operator {{ }} for function arguments is a bit special because it forces the function argument and immediately defuses it. The defused expression is substituted in place, ready to be evaluated in another context, such as the data frame.

我同样对 'bang-bang' 运算符 !! 感到困惑,关于它的文档对于幕后发生的事情同样晦涩难懂。

我的问题不是关于如何使用 运算符,因为它的用法(我认为)非常简单。相反,我想知道这样的运算符实际上是如何在幕后的 {rlang} 中实现的。根据 package authors 之一, {{ foo }} 基本上变成了 !!rlang::enquo(foo)。然而,我仍然无法理解像这样的非标准运算符实际上是如何实现的,特别是考虑到这个似乎“正常工作”,不管它是否被使用{rlang} 函数。 实际上,它适用于由 {rlang} 支持的函数 - 感谢@Konrad Rudolph 的更正。

查看the source code我只能猜测它是用 C 或 C++ 完成的。谁能给我更多信息?

最佳答案

However I'm still at a loss to understand how non-standard operators like this are actually implemented, especially considering that this one seems to 'just work', regardless of whether it's being used by {rlang} functions.

“仅适用于”任意函数——相反:函数确实需要注意整洁的评估。正如您可能猜到的那样,没有 {{ 运算符。相反,“rlang”使用 NSE 来捕获未评估的参数,然后检查表达式的解析树是否包含两个嵌套的 { 调用。然后它采用未计算的表达式并适本地转换它。

关于r - {rlang }'s ' curly-curly'运算符 `{{`是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69454090/

相关文章:

ruby - define_method 的一些问题

sql - 一次在 SQL 查询中选择 100 多个列(但不是所有表列)的便捷方法?

c - 通过 C+GSL 模拟与通过 R 并行模拟

r - dplyr 中的选择函数出错

r - 列表列数据框中的 purrr pmap

r - 当在几何中指定数据时,合并 map 上的图例

c++ - 如果类型的大小大于 X,如何实现接受类型并计算引用的类型特征?

r - R : Error in h2o. init() : H2O failed to start, 中的 H2O 初始化错误停止执行

r - 包 ‘diamonds’ 不可用(对于 R 版本 3.0.0)

r - 在 tidyverse 中动态添加多列