How to Use The New Pipe in R 4.1
A simple new pipe expands readability options in R Programming
When a function is being created in a programming language, updates to that language can create new headaches in maintenance — a developer has to rewrite a section of code so that it is recognized. But in the case of R, a new base function is offering some simplicity in nesting lines of code.
R 4.1 introduced a pipe operator symbol, |>. It is the first time a pipe has been incorporated as a base function. The change is small, but the impact of simplifying code is significant.
Pipes are an operator meant to link one function after another. Pipes are set up with a symbol between the left side and right side of the expression. The pipes are read as “and then” in the line.
So in the image below, for example, line 20 is taking the first 8 rows in the dataframe mtcars, a built-in practice table of automobile specifications. So the line is read in the following way: assign mtcars to the object carslice “and then” apply the slice function to return rows 1 through 8.