Looks up key in defaults. If present and passes validator (when
supplied), returns the stored value; otherwise returns fallback.
Uses standard if/else instead of vectorized ifelse() to avoid
silent truncation of multi-valued defaults.
Arguments
- defaults
A named list of default values, or NULL.
- key
Character string — the name to look up.
- fallback
The value to return when
keyis absent or fails validation.- validator
An optional single-argument predicate function (e.g.,
is.numeric,is.logical). When supplied, the stored value is returned only ifvalidator(value)isTRUE.