Introduction

Here I demonstrate the beauty of using ViewPipeSteps version 0.1.0 package to reveal what goes on at every step of piping in R. I think this is really important in trouble shooting/debugging and explaining what goes on in the piping process.

head(mtcars) %P>% 
  select(cyl, mpg, qsec) %P>% 
  filter(cyl == 6) %P>% 
  mutate(var_x = mpg / qsec) %P>%
  arrange(var_x)
## Printing head(mtcars) %>% select(cyl, mpg, qsec) %>% filter(cyl == 6) %>% mutate(var_x = mpg/qsec)
## # A tibble: 4 x 4
##     cyl   mpg  qsec var_x
##   <dbl> <dbl> <dbl> <dbl>
## 1     6  21    16.5 1.28 
## 2     6  21    17.0 1.23 
## 3     6  21.4  19.4 1.10 
## 4     6  18.1  20.2 0.895
## Printing head(mtcars) %>% select(cyl, mpg, qsec) %>% filter(cyl == 6)
## # A tibble: 4 x 3
##     cyl   mpg  qsec
##   <dbl> <dbl> <dbl>
## 1     6  21    16.5
## 2     6  21    17.0
## 3     6  21.4  19.4
## 4     6  18.1  20.2
## Printing head(mtcars) %>% select(cyl, mpg, qsec)
## # A tibble: 6 x 3
##     cyl   mpg  qsec
##   <dbl> <dbl> <dbl>
## 1     6  21    16.5
## 2     6  21    17.0
## 3     4  22.8  18.6
## 4     6  21.4  19.4
## 5     8  18.7  17.0
## 6     6  18.1  20.2
## Printing head(mtcars)
## # A tibble: 6 x 11
##     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
##   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1  21       6   160   110  3.9   2.62  16.5     0     1     4     4
## 2  21       6   160   110  3.9   2.88  17.0     0     1     4     4
## 3  22.8     4   108    93  3.85  2.32  18.6     1     1     4     1
## 4  21.4     6   258   110  3.08  3.22  19.4     1     0     3     1
## 5  18.7     8   360   175  3.15  3.44  17.0     0     0     3     2
## 6  18.1     6   225   105  2.76  3.46  20.2     1     0     3     1
##                cyl  mpg  qsec     var_x
## Valiant          6 18.1 20.22 0.8951533
## Hornet 4 Drive   6 21.4 19.44 1.1008230
## Mazda RX4 Wag    6 21.0 17.02 1.2338425
## Mazda RX4        6 21.0 16.46 1.2758202

References

Allaire, JJ, Yihui Xie, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, Hadley Wickham, Joe Cheng, Winston Chang, and Richard Iannone. 2021. Rmarkdown: Dynamic Documents for r. https://CRAN.R-project.org/package=rmarkdown.
R Core Team. 2021. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Ranzolin, David, and Joachim Gassen. 2021. ViewPipeSteps: Create View Tabs of Pipe Chains. https://CRAN.R-project.org/package=ViewPipeSteps.
Wickham, Hadley, Romain François, Lionel Henry, and Kirill Müller. 2021. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Xie, Yihui. 2014. “Knitr: A Comprehensive Tool for Reproducible Research in R.” In Implementing Reproducible Computational Research, edited by Victoria Stodden, Friedrich Leisch, and Roger D. Peng. Chapman; Hall/CRC. http://www.crcpress.com/product/isbn/9781466561595.
———. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. https://yihui.org/knitr/.
———. 2021. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.
Xie, Yihui, Christophe Dervieux, and Emily Riederer. 2020. R Markdown Cookbook. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown-cookbook.