With R 4.1, the promise pipe operators are by
then, catch, and
finally methods when used in tandem with the function shorthand (\(x) rhs(x)) and |>.
Details
Promise-aware pipe operators, in the style of magrittr.
Like magrittr pipes, these operators can be used to chain together pipelines
of promise-transforming operations. Unlike magrittr pipes, these pipes wait
for promise resolution and pass the unwrapped value (or error) to the rhs
function call.
The > variants are for handling successful resolution, the ! variants are
for handling errors. The T variants of each return the lhs instead of the
rhs, which is useful for pipeline steps that are used for side effects
(printing, plotting, saving).
promise %...>% func()is equivalent topromise %>% then(func).promise %...!% func()is equivalent topromise %>% catch(func).promise %...T>% func()is equivalent topromise %T>% then(func).promise %...T!% func()is equivalent topromise %T>% catch(func)orpromise %>% catch(func, tee = TRUE).
One situation where 3. and 4. above break down is when func() throws an
error, or returns a promise that ultimately fails. In that case, the failure
will be propagated by our pipe operators but not by the
magrittr-plus-function "equivalents".
For simplicity of implementation, we do not support the magrittr feature of
using a . at the head of a pipeline to turn the entire pipeline into a
function instead of an expression.