use_default: Apply a default value whenever a variable is not well-formed

Description Arguments Value See Also Examples

Description

This function provides a functional approach for a specific use case of conditional expressions: that of applying default values when a variable is not well-formed. In this context, well-formedness is considered to be any scalar value that is not NA. By encapsulating this behavior in a function, referential transparency is preserved.

Arguments

x

a scalar variable

default

the value to replace empty, NULL, or NA

Value

A well-formed value, either the original value or the default if x is not well-formed.

See Also

onlyif

Examples

1
2
x <- c(1, 2, 3, NA, NA)
map(x, function(y) use_default(y, 0))

zatonovo/lambda.tools documentation built on May 4, 2019, 9:11 p.m.