## 5.7 Piping Operations

R users are familiar with the pipe operator %>% which allows chaining operations together. That means that the output of an operation will be used as input in the next operation and so on.

This can be accomplished with the @chain macro. To use it, we start with @chain followed by the DataFrame and a begin statement. Every operation inside the begin ... end statement will be used as input for the next operation, therefore chaining operations together.

Here is a simple example with a groupby followed by a @combine:

@chain leftjoined begin
groupby(:name)
end
Sally 1.0
Hank 4.0
Bob 5.0
Alice 8.5

NOTE: @chain will replace the first positional argument while chaining operations. This is not a problem in DataFrames.jl and DataFramesMeta.jl, since the DataFrame is always the first positional argument.

We can also nest as many as begin ... end statements we desired inside the operations:

@chain leftjoined begin
groupby(:name)
@combine begin
end
end
Sally 1.0 9.5
Hank 4.0 6.0
Bob 5.0 5.0
Alice 8.5 5.0

To conclude, let’s show a @chain example with all of the DataFramesMeta.jl macros we covered so far:

@chain leftjoined begin
@rtransform begin
end
groupby(:name)
@combine begin
end