return_if_null: If a Value is NULL, Trigger the Parent Function's Return

return_if_nullR Documentation

If a Value is NULL, Trigger the Parent Function's Return

Description

If the focal input is NULL, return value from the parent function. Should only be used within a function.

Usage

return_if_null(x, value = NULL)

Arguments

x

Focal input.

value

If x is NULL, return this input from the parent function.

Value

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.

Examples

 ff <- function(x = 1, null_return = "hello"){
   return_if_null(x, null_return)
   x
 }
 ff()
 ff(NULL)


portalr documentation built on Sept. 30, 2024, 9:20 a.m.