gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:13:06 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com