3.16 Pipes: Tee Pipe Intermediate Results
20220511 The tee-pipe comes in handy with
base::assign()ing intermediate results into a variable without
breaking the main flow of the pipeline. In the following example the
variable tmp has an intermediate value assigned to it 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.000
## 1st Qu.: 7.40 1st Qu.:19.70 1st Qu.: 6.800
## Median :12.00 Median :24.50 Median : 9.700
## Mean :12.09 Mean :24.89 Mean : 8.708
## 3rd Qu.:16.80 3rd Qu.:29.80 3rd Qu.:11.100
## Max. :33.90 Max. :49.60 Max. :14.500
## NAs :719 NAs :901 NAs :105470
We can now access the variable tmp:
## # A tibble: 171,900 × 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
## 4 0 14.3 25 NA
## 5 0 7.7 26.7 NA
## 6 0 9.7 31.9 NA
## 7 0 13.4 30.4 NA
## 8 0 8.4 24.6 NA
## 9 0 14.1 20.9 NA
## 10 0 9.8 25.6 NA
## # ℹ 171,890 more rows
Notice that for a tee-pipe curly braces will often be used to
encapsulate a sequence of operations for the first path of the
tee-pipe, allowing reference the data from the pipeline as the period
(.).
If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, 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