Skip to contents

The pipe operator (%>%) is a powerful tool for chaining operations in a readable and concise manner. It allows you to pass the left-hand side (lhs) value into the right-hand side (rhs) function call. For detailed information, refer to magrittr::%>%.

Usage

lhs %>% rhs

Arguments

lhs

A value or the magrittr placeholder, representing the initial input to the pipeline.

rhs

A function call or expression that operates on lhs, using magrittr semantics.

Value

The result of evaluating rhs(lhs), enabling seamless chaining of operations.

Examples

# Example: Using the pipe operator to transform data
library(magrittr)
result <- iris %>%
head(10) %>%
subset(Species == "setosa") %>%
summary()
print(result)
#>   Sepal.Length    Sepal.Width     Petal.Length   Petal.Width         Species  
#>  Min.   :4.400   Min.   :2.900   Min.   :1.30   Min.   :0.10   setosa    :10  
#>  1st Qu.:4.625   1st Qu.:3.100   1st Qu.:1.40   1st Qu.:0.20   versicolor: 0  
#>  Median :4.900   Median :3.300   Median :1.40   Median :0.20   virginica : 0  
#>  Mean   :4.860   Mean   :3.310   Mean   :1.45   Mean   :0.22                  
#>  3rd Qu.:5.000   3rd Qu.:3.475   3rd Qu.:1.50   3rd Qu.:0.20                  
#>  Max.   :5.400   Max.   :3.900   Max.   :1.70   Max.   :0.40