%.>% | R Documentation |
This operator pipes an object forward into a function or call expression
using an explicit placement of the dot (.
) placeholder. Unlike magrittr's
%>% operator, %.>%
does not automatically place the
left-hand side (lhs
) as the first argument in the right-hand side (rhs
)
call. This operator provides a simpler alternative to the use of braces with
magrittr, while achieving similar behavior.
lhs %.>% rhs
lhs |
A value to be piped forward. |
rhs |
A function call that utilizes the dot ( |
The %.>%
operator is used to pipe the lhs
value into the rhs
function
call. Within the rhs
expression, the placeholder .
represents the
position where lhs
will be inserted. This provides more control over where
the lhs
value appears in the rhs
function call, compared to the magrittr
pipe operator which always places lhs
as the first argument of rhs
.
Unlike magrittr's pipe, which may require the use of braces to fully control
the placement of lhs
in nested function calls, %.>%
simplifies this by
directly allowing multiple usages of the dot placeholder without requiring
braces. For example, the following expression using magrittr's pipe and
braces:
library(magrittr) 1:10 %>% { c(min(.), max(.)) }
can be written as:
1:10 %.>% c(min(.), max(.))
without needing additional braces.
The disadvantage of %.>%
is that you always need to use
the dot placeholder, even when piping to the first argument of the
right-hand side (rhs
).
No Return Value.
# Equivalent to `subset(head(iris), 1:nrow(head(iris)) %% 2 == 0)`
head(iris) %.>% subset(., 1:nrow(.) %% 2 == 0)
# Equivalent to `c(min(1:10), max(1:10))`
1:10 %.>% c(min(.), max(.))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.