语法 %||% 的含义是什么? [英] What is meaning of the syntax %||%?

查看:134
本文介绍了语法 %||% 的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个动态 UI,所以我使用了此代码

I'm trying to create a dynamic UI, so i used this code

output$col <- renderUI({
    map(col_names(), ~ textInput(.x, NULL, value = isolate(input[[.x]])) %||% "")
  })

来自:

https://mastering-shiny.org/action-dynamic.html#multiple-controls

我的问题基本上是,语法 %||% 的含义是什么?

My question is basically, what is meaning of the syntax %||% ?

推荐答案

帮助页面说明:

?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 会像错误消息一样显示

It is similar to a coalesce function. Basically, whenever the input is NULL, that means it is not (yet) available, an empty tring is assigned rather than NULL. This is desireable because this is rendered and displayed as an empty value should. NULL would be shown like an error massage

这篇关于语法 %||% 的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆