![](/img/trans.png)
[英]What does the !! operator mean in R, particularly in the context !!sym("x")
[英]What does the %||% operator mean in R?
在下面的R代码段(来自调试器)中,第8行中的%||%运算符是什么意思?
function (env = caller_env(), default = NULL)
{
out <- switch_type(env, environment = env, definition = ,
formula = attr(env, ".Environment"), primitive = base_env(),
closure = environment(env), list = switch_class(env,
frame = env$env))
out <- out %||% default
if (is_null(out)) {
type <- friendly_type(type_of(env))
abort(paste0("Can't extract an environment from ", type))
}
else {
out
}
}
谢谢你的帮助!
%||%
不是R语言的一部分。 在GitHub上快速搜索提供的代码会生成rlang
包。
library(rlang)
`%||%`
导致:
function (x, y)
{
if (is_null(x))
y
else x
}
<environment: namespace:rlang>
换句话说,如果不为NULL
,则返回左侧,否则返回右侧。
该运算符在tidyverse中被广泛使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.