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

Pipes: Tee Pipe Intermediate Results

20210103 A use of the tee-pipe that can come in handy is to base::assign() intermediate results into a variable without breaking the main flow of the pipeline. The variable tmp in the following tee-pipe is assigned to within the base::globalenv() so that we can access it from anywhere in the R session.
ds %>%
  select(rainfall, min_temp, max_temp, sunshine) %>%
  filter(rainfall==0) %T>%
  {assign("tmp", ., globalenv())}  %>%
  select(min_temp, max_temp, sunshine) %>%
  summary()
##     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  
##  3rd Qu.:16.90   3rd Qu.:30.00   3rd Qu.:11.10  
....

We can now access the variable tmp:

print(tmp)
## # 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
##  3        0      9.2     28         NA
....

Notice the use of the curly braces for the first path of the tee-pipe. This allows us to reference the data from the pipeline as the period (.).


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.