Setup
library(tidyverse)
library(thinkr)
thinkr::peep()
: See intermediate stages of piped dfsJune 1, 2023
Insert thinkr::peep(head)
into a df
pipeline to print a few rows at a particular intermediate stage in the pipeline. Here it prints a few lines of the df
before it gets summarized:
palmerpenguins::penguins |>
peep(head) |>
group_by(species) |>
summarize(across(where(is.numeric), \(x) mean(x, na.rm = TRUE)))
# A tibble: 6 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
# ℹ 2 more variables: sex <fct>, year <int>
species | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | year |
---|---|---|---|---|---|
Adelie | 38.79139 | 18.34636 | 189.9536 | 3700.662 | 2008.013 |
Chinstrap | 48.83382 | 18.42059 | 195.8235 | 3733.088 | 2007.971 |
Gentoo | 47.50488 | 14.98211 | 217.1870 | 5076.016 | 2008.081 |
You can use multiple functions, like head
and tail
to see two views of the intermediate step; verbose = TRUE
prints the functions used for these peeps:
palmerpenguins::penguins |>
peep(head, tail, verbose = TRUE) |>
group_by(species) |>
summarize(across(where(is.numeric), \(x) mean(x, na.rm = TRUE)))
head(.)
# A tibble: 6 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
# ℹ 2 more variables: sex <fct>, year <int>
tail(.)
# A tibble: 6 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Chinstrap Dream 45.7 17 195 3650
2 Chinstrap Dream 55.8 19.8 207 4000
3 Chinstrap Dream 43.5 18.1 202 3400
4 Chinstrap Dream 49.6 18.2 193 3775
5 Chinstrap Dream 50.8 19 210 4100
6 Chinstrap Dream 50.2 18.7 198 3775
# ℹ 2 more variables: sex <fct>, year <int>
species | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | year |
---|---|---|---|---|---|
Adelie | 38.79139 | 18.34636 | 189.9536 | 3700.662 | 2008.013 |
Chinstrap | 48.83382 | 18.42059 | 195.8235 | 3733.088 | 2007.971 |
Gentoo | 47.50488 | 14.98211 | 217.1870 | 5076.016 | 2008.081 |
And you can include arguments to functions inside peep()
with dot syntax if you’re using the magrittr
pipe %>%
(at least for the line directly above the peep
):1
palmerpenguins::penguins %>%
peep(head(n = 7, x = .)) |>
group_by(species) |>
summarize(across(where(is.numeric), \(x) mean(x, na.rm = TRUE)))
# A tibble: 7 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
7 Adelie Torgersen 38.9 17.8 181 3625
# ℹ 2 more variables: sex <fct>, year <int>
species | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | year |
---|---|---|---|---|---|
Adelie | 38.79139 | 18.34636 | 189.9536 | 3700.662 | 2008.013 |
Chinstrap | 48.83382 | 18.42059 | 195.8235 | 3733.088 | 2007.971 |
Gentoo | 47.50488 | 14.98211 | 217.1870 | 5076.016 | 2008.081 |
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.3.1 (2023-06-16)
os macOS Ventura 13.4.1
system aarch64, darwin20
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/Chicago
date 2023-07-08
pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
─ Packages ───────────────────────────────────────────────────────────────────
package loadedversion date source
askpass 1.1 2019-01-13 CRAN (R 4.3.0)
assertthat 0.2.1 2019-03-21 CRAN (R 4.3.0)
cachem 1.0.8 2023-05-01 CRAN (R 4.3.0)
callr 3.7.3 2022-11-02 CRAN (R 4.3.0)
cli 3.6.1 2023-03-23 CRAN (R 4.3.0)
codetools 0.2-19 2023-02-01 CRAN (R 4.3.1)
colorspace 2.1-0 2023-01-23 CRAN (R 4.3.0)
crayon 1.5.2 2022-09-29 CRAN (R 4.3.0)
crul 1.3 2022-09-03 CRAN (R 4.3.1)
curl 5.0.0 2023-01-12 CRAN (R 4.3.0)
devtools 2.4.5 2022-10-11 CRAN (R 4.3.0)
digest 0.6.31 2022-12-11 CRAN (R 4.3.0)
dplyr 1.1.2 2023-04-20 CRAN (R 4.3.0)
ellipsis 0.3.2 2021-04-29 CRAN (R 4.3.0)
evaluate 0.21 2023-05-05 CRAN (R 4.3.0)
fansi 1.0.4 2023-01-22 CRAN (R 4.3.0)
fastmap 1.1.1 2023-02-24 CRAN (R 4.3.0)
fontBitstreamVera 0.1.1 2017-02-01 CRAN (R 4.3.0)
fontLiberation 0.1.0 2016-10-15 CRAN (R 4.3.0)
fontquiver 0.2.1 2017-02-01 CRAN (R 4.3.0)
forcats 1.0.0 2023-01-29 CRAN (R 4.3.0)
fs 1.6.2 2023-04-25 CRAN (R 4.3.0)
gdtools 0.3.3 2023-03-27 CRAN (R 4.3.0)
generics 0.1.3 2022-07-05 CRAN (R 4.3.0)
gfonts 0.2.0 2023-01-08 CRAN (R 4.3.0)
ggplot2 3.4.2 2023-04-03 CRAN (R 4.3.0)
glue 1.6.2 2022-02-24 CRAN (R 4.3.0)
gtable 0.3.3 2023-03-21 CRAN (R 4.3.0)
hms 1.1.3 2023-03-21 CRAN (R 4.3.0)
htmltools 0.5.5 2023-03-23 CRAN (R 4.3.0)
htmlwidgets 1.6.2 2023-03-17 CRAN (R 4.3.0)
httpcode 0.3.0 2020-04-10 CRAN (R 4.3.0)
httpuv 1.6.11 2023-05-11 CRAN (R 4.3.0)
jsonlite 1.8.4 2022-12-06 CRAN (R 4.3.0)
knitr 1.43 2023-05-25 CRAN (R 4.3.0)
later 1.3.1 2023-05-02 CRAN (R 4.3.0)
lazyeval 0.2.2 2019-03-15 CRAN (R 4.3.0)
lifecycle 1.0.3 2022-10-07 CRAN (R 4.3.0)
lubridate 1.9.2 2023-02-10 CRAN (R 4.3.0)
magrittr 2.0.3 2022-03-30 CRAN (R 4.3.0)
memoise 2.0.1 2021-11-26 CRAN (R 4.3.0)
mime 0.12 2021-09-28 CRAN (R 4.3.0)
miniUI 0.1.1.1 2018-05-18 CRAN (R 4.3.0)
munsell 0.5.0 2018-06-12 CRAN (R 4.3.0)
officer 0.6.2 2023-03-28 CRAN (R 4.3.0)
openssl 2.0.6 2023-03-09 CRAN (R 4.3.0)
palmerpenguins 0.1.1 2022-08-15 CRAN (R 4.3.0)
pillar 1.9.0 2023-03-22 CRAN (R 4.3.0)
pkgbuild 1.4.0 2022-11-27 CRAN (R 4.3.1)
pkgconfig 2.0.3 2019-09-22 CRAN (R 4.3.0)
pkgload 1.3.2 2022-11-16 CRAN (R 4.3.0)
prettyunits 1.1.1 2020-01-24 CRAN (R 4.3.0)
processx 3.8.1 2023-04-18 CRAN (R 4.3.0)
profvis 0.3.7 2020-11-02 CRAN (R 4.3.1)
promises 1.2.0.1 2021-02-11 CRAN (R 4.3.0)
ps 1.7.5 2023-04-18 CRAN (R 4.3.0)
purrr 1.0.1 2023-01-10 CRAN (R 4.3.0)
R6 2.5.1 2021-08-19 CRAN (R 4.3.0)
ragg 1.2.5 2023-01-12 CRAN (R 4.3.0)
Rcpp 1.0.10 2023-01-22 CRAN (R 4.3.0)
readr 2.1.4 2023-02-10 CRAN (R 4.3.0)
remotes 2.4.2 2021-11-30 CRAN (R 4.3.0)
renv 0.17.3 2023-04-06 CRAN (R 4.3.0)
rlang 1.1.1 2023-04-28 CRAN (R 4.3.0)
rmarkdown 2.21 2023-03-26 CRAN (R 4.3.0)
rstudioapi 0.14 2022-08-22 CRAN (R 4.3.0)
rvg 0.3.2 2023-01-07 CRAN (R 4.3.0)
scales 1.2.1 2022-08-20 CRAN (R 4.3.0)
sessioninfo 1.2.2 2021-12-06 CRAN (R 4.3.0)
shiny 1.7.4 2022-12-15 CRAN (R 4.3.0)
stringi 1.7.12 2023-01-11 CRAN (R 4.3.0)
stringr 1.5.0 2022-12-02 CRAN (R 4.3.0)
systemfonts 1.0.4 2022-02-11 CRAN (R 4.3.0)
textshaping 0.3.6 2021-10-13 CRAN (R 4.3.0)
thinkr 0.16 2022-08-22 CRAN (R 4.3.0)
tibble 3.2.1 2023-03-20 CRAN (R 4.3.0)
tidyr 1.3.0 2023-01-24 CRAN (R 4.3.0)
tidyselect 1.2.0 2022-10-10 CRAN (R 4.3.0)
tidyverse 2.0.0 2023-02-22 CRAN (R 4.3.0)
timechange 0.2.0 2023-01-11 CRAN (R 4.3.0)
tzdb 0.3.0 2022-03-28 CRAN (R 4.3.0)
urlchecker 1.0.1 2021-11-30 CRAN (R 4.3.0)
usethis 2.1.6 2022-05-25 CRAN (R 4.3.1)
utf8 1.2.3 2023-01-31 CRAN (R 4.3.0)
uuid 1.1-0 2022-04-19 CRAN (R 4.3.0)
vctrs 0.6.2 2023-04-19 CRAN (R 4.3.0)
withr 2.5.0 2022-03-03 CRAN (R 4.3.0)
xfun 0.39 2023-04-20 CRAN (R 4.3.0)
xml2 1.3.4 2023-04-27 CRAN (R 4.3.0)
xtable 1.8-4 2019-04-21 CRAN (R 4.3.0)
yaml 2.3.7 2023-01-23 CRAN (R 4.3.0)
zip 2.3.0 2023-04-17 CRAN (R 4.3.0)
You can’t use the base pipe’s placeholder, _
, here, since it does not work in nested functions.↩︎