Description Usage Arguments Value Examples
The operator is useful as a way of providing a default value
in case the output of another function is NULL
or its length is
zero.
1 | a %if_null_or_len0% b
|
a |
An expression. |
b |
An alternative. |
If !is.null(a) & length(a) > 0 & nchar(a) > 0
is TRUE
returns a
, otherwise returns b
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | a1 <- "Default value"
a2 <- NULL
a3 <- character()
b <- "Alternative"
VECTOR <- c("Alternative", "Alternative")
a1 %if_null_or_len0% b
#> [1] "Default value"
a2 %if_null_or_len0% b
#> "Alternative"
a3 %if_null_or_len0% b
#> "Alternative"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a1 %if_null_or_len0% VECTOR
#> [1] "Default value"
a2 %if_null_or_len0% VECTOR
#> "Alternative"
VECTOR %if_null_or_len0% a1
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.