I am using the tidyverse to filter out a dataframe and would like a print at each step of the dimensions (or nrows) of the intermediate objects. I thought I could simply use
@akrun's idea works, but it's not idiomatic tidyverse. Other functions in the tidyverse, like print() and glimpse() return the data parameter invisibly so they can be piped without resorting to {}. Those {} make it difficult to clean up pipes after your done exploring what's going on.
Try:
library(tidyverse)
tidydim <- function(x) {
print(dim(x))
invisible(x)
}
mtcars %>%
filter(cyl > 4) %>%
tidydim() %>%
filter(., am == 0) %>%
tidydim() %>%
filter(., disp >= 200) %>%
tidydim()
That way your "cleanup" (i.e. not producing interim console output) canbe to quickly/easily remove the tidydim() lines or remove the print(…) from the function.