![](/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.