The package provides “named pipes” which may complement:
the magrittr package pipes. The named pipes make it possible
to use all lower-case and upper-case letters as the right-hand-side
placeholders for the values piped from the left-hand-side,
while the standard magrittr's operator %>%
uses only a dot.
When the package is loaded (via library(AlphaPipes)
)
the pipe operators (%a%
... %z%
and %A%
... %Z%
)
are dynamically created in AlphaPipes' namespace.
So you cannot import them via %myoperator% <- AlphaPipes::`%a%`
.
Anyway, such an import does not seem to make sense – namespaced operators
e.g. AlphaPipes::`%a%`
would be inconvenient – too verbose,
while re-named named pipes e.g. %aa%
as an alias for %a%
would be confusing
(since symbol a
would need to be used on the right-hand side anyway).
AlphaPipes needs package clojR which can be installed from GitHub:
devtools::install_github('alekrutkowski/clojR')
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Trivial:
1:3 %A% mean(A) # The same as mean(1:3) or 1:3 %>% mean
# Returns 2
# Showing the actual usefulness - referring to earlier values
# from the piped flow:
data.frame(xx=1:5) %a%
(dplyr::mutate(a, nnn = xx+10) %b%
dplyr::rename(b, xx2 = xx) %b%
cbind(b, a))
# Returns a data.frame:
# xx2 nnn xx
# 1 1 11 1
# 2 2 12 2
# 3 3 13 3
# 4 4 14 4
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.