3.15 Pipes: Tee Pipe

20220511 Another useful operation is the tee-pipe %T>% which causes the command that follows to be run as a side-pipe, piping the same data into that command and also into the then following command and the rest of the pipeline. The output from the first command is ignored, except for its side-effect, which might be to base::print() the intermediate results as shown below or to store the intermediate results before further processing, as in Section 3.16.

In the following example the tee-pipe processes the transformed dataset in two ways—once with base::print(), then continuing on with dplyr::select() and base::summary(). The tee-pipe splits the flow in these two directions with the second flow continuing the sequence of the pipeline.

ds %>%
  select(rainfall, min_temp, max_temp, sunshine) %>%
  filter(rainfall==0) %T>%
  print()  %>%
  select(min_temp, max_temp, sunshine) %>%
## # A tibble: 141,400 × 4
##    rainfall min_temp max_temp sunshine
##       <dbl>    <dbl>    <dbl>    <dbl>
##  1        0      7.4     25.1       NA
##  2        0     12.9     25.7       NA
##     min_temp        max_temp        sunshine    
##  Min.   :-8.70   Min.   :-2.10   Min.   : 0.00  
##  1st Qu.: 7.40   1st Qu.:19.70   1st Qu.: 6.80  
##  Median :12.10   Median :24.50   Median : 9.70  
##  Mean   :12.11   Mean   :24.86   Mean   : 8.71  

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0