x_to_monad: Conversions to monads

Description Usage Arguments Details Examples

Description

These functions convert possibly non-monadic inputs into monads.

Usage

1
2
3
4
5
6
as_monad(expr, desc = NULL, tag = .default_tag(), doc = .default_doc(),
  key = NULL, env = parent.frame(), lossy = FALSE)

funnel(..., env = parent.frame(), keep_history = TRUE)

combine(xs, keep_history = TRUE, desc = .default_code())

Arguments

expr

An expression

desc

A description of the monad (usually the producing code)

tag

Character vector specifying the tag to associate with a node

doc

A docstring to associate with the monad

key

16 byte raw vector

env

Evaluation environment

lossy

logical Should unnesting with record be done?

...

multiple expressions

keep_history

merge the histories of all monads

xs

A list of elements to join into a monad

Details

For each of these functions, failure of any part causes failure of the whole. Any non-monadic inputs will be converted to monads. Any exceptions raised in the inputs will be caught.

as_monad evaluate a single expression into an Rmonad. If the value is already an Rmonad, it will be nested.

funnel evaluates multiple arguments into one Rmonad. It can be used within pipelines to create multi-input nodes (works well with %*>%).

combine takes a list of Rmonads and joins the elements into one Rmonad. The values of the original monadic containers joined into a list in the child Rmonad. The list Rmonads are recorded as the new Rmonad's parents.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
as_monad(stop(1))
as_monad(1:10)
as_monad(5 %>>% sqrt)

## merge failing inputs 
funnel( 1:10, stop(1), sqrt(-3:3) )

## join pipelines
b2 <- letters[1:10] %>>% sqrt
b3 <- -3:6 %>>% log
1:10 %>% funnel(b2,b3) %>>%
  {data.frame(b1=.[[1]], b2=.[[2]], b3=.[[3]])}

z <- list(
  x = rnorm(10) %>>% sqrt,
  y = 1 %>>% colSums
)
combine(z)

rmonad documentation built on March 18, 2018, 2:13 p.m.