What is meaning of the syntax %||%?

前端 未结 2 1531
臣服心动
臣服心动 2021-01-28 14:36

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]])) %||         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 14:53

    The help page of sheds light into it:

    ?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.
    

    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

提交回复
热议问题