Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Tee Pipe

20210103 Another useful operation is the tee-pipe magrittr::https://www.rdocumentation.org/packages/magrittr/topics/as a side-pipe whilst 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 below or to store the intermediate results before further processing, as in Section [*]. A common use case is to whilst continuing on to assign the dataset itself to a variable. We will often see the following example.
# Demonstrate usage of a tee-pipe.

no_rain <-
  ds %>%
  filter(rainfall==0) %T>%
  print()
## # A tibble: 112,447 x 24
##    date       location min_temp max_temp rainfall evaporation sunshine
##    <date>     <chr>       <dbl>    <dbl>    <dbl>       <dbl>    <dbl>
##  1 2008-12-02 Albury        7.4     25.1        0          NA       NA
##  2 2008-12-03 Albury       12.9     25.7        0          NA       NA
....

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 two directions. The second flow continues the sequence of the pipeline.

ds %>%
  select(rainfall, min_temp, max_temp, sunshine) %>%
  filter(rainfall==0) %T>%
  print()  %>%
  select(min_temp, max_temp, sunshine) %>%
  summary()
## # A tibble: 112,447 x 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.80   1st Qu.: 6.90  
##  Median :12.10   Median :24.60   Median : 9.70  
##  Mean   :12.15   Mean   :24.97   Mean   : 8.72  
....


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.