r - 语法 %||% 的含义是什么?
问题描述
我正在尝试创建一个动态 UI,所以我使用了这段代码
output$col <- renderUI({
map(col_names(), ~ textInput(.x, NULL, value = isolate(input[[.x]])) %||% "")
})
从 :
https://mastering-shiny.org/action-dynamic.html#multiple-controls
我的问题基本上是,语法 %||% 的含义是什么?
解决方案
帮助页面揭示了它:
?rlang::`%||%`
Description
This infix function makes it easy to replace NULLs with a default value.
It's inspired by the way that Ruby's or operation (||) works.
Usage
x %||% y
Arguments
x, y
If x is NULL, will return y; otherwise returns x.
它类似于合并函数。基本上,每当输入为 NULL 时,这意味着它(尚)不可用,分配一个空字符串而不是NULL
. 这是可取的,因为它应该被渲染和显示为空值。NULL 会像错误消息一样显示
推荐阅读
- parse-platform - 将云功能从 Parse-server 2.0 升级到 3.0
- java - hibernate @ColumnTransformer 不适用于更新命名查询
- r - RShiny 中的字符串类型全局变量
- angular - 角激活路线获取参数 - 不工作
- reactjs - React - 领域结果作为对象列表
- javascript - flowtype 无法返回对象文字,因为对象类型不兼容
- php - Yii2 在生产中显示白屏错误
- reactjs - 关键帧在 MUI 样式的组件中不起作用
- python - 我怎样才能渲染神社表?
- java - 如何修复代码,使其可以使用 for-loop 运行 5 次?