Dot Pipe

John Mount


%.>% dot arrow pipe is a strict pipe with intended semantics:

a %.>% b” is to be treated as if the user had written “{ . <- a; b };” with “%.>%” being treated as left-associative.

That is: %.>% does not alter any function arguments that are not explicitly named. %.>% is designed to be explicit and simple.

The effect looks is show below.

The following two expressions should be equivalent:


## [1] 0.8919465
4 %.>% sin(.) %.>% exp(.) %.>% cos(.)
## [1] 0.8919465

The notation is quite powerful as it treats pipe stages as expression parameterized over the variable “.”. This means you do not need to introduce functions to express stages. The following is a valid dot-pipe:

1:4 %.>% .^2 
## [1]  1  4  9 16

The notation is also very regular in that many variations of expression work as expected. Example:

5 %.>% sin(.)
## [1] -0.9589243
5 %.>% base::sin(.)
## [1] -0.9589243

Regularity can be a big advantage in teaching and comprehension. Please see “In Praise of Syntactic Sugar” for discussion.

For more of the details on dot pipe please see the package README and the following technical article.