If the focal input is NULL, return value from the parent function. Should only be used within a function.
return_if_null(x, value = NULL)Focal input.
If x is NULL, return this input from the parent function.
If x is not NULL, NULL is returned. If x is NULL, the result of return with value as its input evaluated within the parent function's environment is returned.
ff <- function(x = 1, null_return = "hello"){
return_if_null(x, null_return)
x
}
ff()
#> [1] 1
ff(NULL)
#> [1] "hello"