Conditional execution of one of two branches based on a scalar boolean
predicate, mirroring R's if construct: it branches between two
functions and evaluates only the selected one. Its arguments are named
after that construct, where prim_ifelse() – which selects
element-wise between two arrays – is named after ifelse().
Arguments
- pred
(
arrayish)
Predicate deciding which branch to execute. Must be a scalar of the boolean data type, or an R logical.- true, false
(
function())
Zero-argument functions for the true and false branches. Both must return outputs of the same structure, data types and shapes. As withprim_ifelse(), whose two values must already agree, nothing is promoted: branches that disagree are an error.
Value
(arrayish | list)
Result of the executed branch: an array, or a tree of them in the sense
of pjrt's RTree – a list, nested arbitrarily – with
the structure, data types and shapes both branches share.