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.
Arguments
- lhs
A value to be piped forward.
- rhs
A function call that utilizes the dot (
.
) placeholder to specify wherelhs
should be placed.
Details
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:
can be written as:
without needing additional braces.
Examples
# Equivalent to `subset(head(iris), 1:nrow(head(iris)) %% 2 == 0)`
head(iris) %.>% subset(., 1:nrow(.) %% 2 == 0)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 2 4.9 3.0 1.4 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa
# Equivalent to `c(min(1:10), max(1:10))`
1:10 %.>% c(min(.), max(.))
#> [1] 1 10