The wrapr dot arrow pipe
was designed
to both be an effective R
function application pipe and also an experimental test-bed for
pipe effects.
Let's take a look at implementing a new effect from a user perspective. The idea we want to implement is delayed evaluation through a
collecting object we call a "locum" or stand-in. The locum is intended to collect operations without executing them, for later use. This is similar to a lambda or function abstraction. The code is now in the wrapr
package, but could be implemented by any user as it uses only public or semi-public wrapr
interfaces.
The locum
was for a while a part of wrapr
, but now it is user code in the file locum.R
.
Let's start loading the wrapr
package.
library(wrapr) source("locum.R")
We can use the locum
to collect the operations, and then print them.
y <- 4 p <- locum() %.>% sin(.) %.>% cos(.) %.>% atan2(., y) print(p)
We can now replace the locum
with the value we want to apply the pipeline to.
5 %.>% p
This yields the same answer as the following function application.
atan2(cos(sin(5)), 4)
We can also add later intended arguments to the pipeline formatting.
print(p, 'start' = 4)
We can do some fun things, such as combining locum
pipelines.
p1 <- locum() %.>% sin(.) p2 <- locum() %.>% cos(.) p12 <- p1 %.>% p2 p12
4 %.>% p12
cos(sin(4))
The idea is: wrapr
dot arrow pipe is designed for expansion through the apply_right
, apply_left
S3
interfaces, and the apply_right_S4
S4
interface. And users can access the implementation through the pipe_impl
function. This example and the formal article should give users a good place to start. rquery
, rqdatatable
, and cdata
already use the extension interfaces to implement interesting features.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.