- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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} 支持的函数 - 感谢@Konrad Rudolph 的更正。{rlang}
函数。
查看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/
我从文档中可以看到rlang::enquo()和rlang::quo()用于不同的上下文。因此,我使用了 rlang::enysm()最近在函数声明中(见下文)。然而,在另一个 SE 函数调用中,我收
我正在尝试编写一个有点复杂的自定义函数,因此为了简单起见,我创建了玩具示例。 假设我想编写一个函数 - 自动决定运行适当的函数:例如,t 检验或方差分析。 接受“带引号” 和不带引号 参数 所以我编写
当我建立像决策树、随机森林这样的机器学习分类模型时,我会遇到错误。更新程序包(标准程序包)
我再次对 rlang 的文档感到困惑和错误信息。我使用双刘海和三刘海尝试了 20 次不同的迭代,:= , quo , enquo , ensym ,以及所有其他名称不明确的 rlang 函数。 如果您
我使用 memoise 包将查询缓存到 arrow 数据集,但我有时会在哈希中遇到不匹配/“冲突”,因此会返回错误的值。 我已经隔离了问题并将其复制到下面的 MWE 中。问题在于,首先过滤然后汇总的箭
假设我想计算 mean , min和 max对于自定义函数中任意数量的组。 玩具数据如下所示: library(tidyverse) df % gather(Variable, Value, -c
我创建了一个函数来将函数名转换为字符串。版本 1 func_to_string1 运行良好,但版本 2 func_to_string2 不起作用。 func_to_string1 func_to_s
我正在编写一个函数,其中我提供一个变量名作为符号。在函数的不同步骤中,我想将变量名称用作字符串。根据文档,rlang::as_string“将符号转换为字符串。” 这是一个基本的例子。此函数返回带有标
我正在写一个包,我的一个函数生成了一个 ggplot。我只想导入 ggplot2 或 rlang(不依赖于它们)。经过一些尝试和错误后,我设法让它工作,但现在我不确定为什么它能工作。 所以我的问题是,
我正在编写一个使用 tidyverse 函数的包,即使用非标准评估,如 dplyr::filter例如: setMethod("filter_by_id", signature(x
是否可以使用 rlang 整洁评估运算符 {{在 lm 公式中? 我知道您可以使用双花括号来定义一个通用函数,例如: my_scatter <- function(df, xvar, yvar) {
假设我有一个函数 f,它接受一堆参数,以及一个可选的额外参数。 f <- function(..., extra) { arglst <- lapply(quos(...), get_expr
说我有一个嵌套列表 tmp rlang::flatten(tmp) $a [1] 1 [[2]] [[2]]$x [1] 1 [[2]]$y [1] "a" [[3]] [[3]]$z [1] 2
文档表明这是可能的: fn % base::as.list() tmp %>% stringr::str_detect('x') %>%
我正在尝试创建一个字符串,其中包含“大括号”和用户基于的对象。然后我将在 ggplot 命令中解析和评估这个表达式。 test_func % rlang::expr() df %>%
有时,在使用 dplyr 时,会有一个列名称的字符向量,用于对数据进行操作,例如: cols_of_interest % select_(.dots = my_cols) 现在已弃用 verb_
我希望有人能帮助我解决我的代码的问题。我花了大约 5 个小时试图找出代码的问题,并检查了这些链接 1 , 2但无法找出我的代码的问题我正在尝试构建一个 Shiny 的应用程序,但是当我运行代码时,我不
我正在构建一个函数,我希望用户能够为其传递未加引号的变量。稍后,在准备输出时,我将需要这些变量的名称作为字符串。 如果每个参数只携带一个变量,这没有问题。我可以使用 deparse(substitut
我正在尝试安装 tidyr 的开发版本。当我尝试 devtools::install_github("tidyverse/tidyr") 或 remotes::install_github("tidy
我希望有人能帮助我解决我的代码的问题。我花了大约 5 个小时试图找出代码的问题,并检查了这些链接 1 , 2但无法找出我的代码的问题我正在尝试构建一个 Shiny 的应用程序,但是当我运行代码时,我不
我是一名优秀的程序员,十分优秀!