null_switch: Evaluate Expressions until not NULL

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Evaluates expressions until one that is not NULL is encountered and returns that. Expressions after the first non-NULL result are not evaluated. If all expressions are NULL, it will return NULL

Usage

1

Arguments

...

expressions to try to evaluate

Value

The result of evaluating one of the expressions. Will only be NULL if they all evaluated to NULL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
f <- function() {
  cat("Evaluating f\n")
  NULL
}
g <- function() {
  cat("Evaluating g\n")
  2
}

null_switch(NULL, f(), g())
null_switch(NULL, g(), f())
null_switch(f(), f(), f())

rando documentation built on Feb. 16, 2021, 5:07 p.m.