View source: R/dplyr_wrappers.R
tunnel | R Documentation |
Within a dplyr-pipe, you might want to print a summary statistic or run some other function before continuing to process or save the original data. This function does that by taking a dataframe and function as arguments, printing the result of the function and returning the dataframe for further processing.
tunnel(df, fun, ..., note = NULL, return = TRUE)
df |
A dataframe |
fun |
A function that is applied to the dataframe and the output of which is printed. If the argument is not passed, df is merely printed and not returned, which only makes sense in combination with the 'note' argument |
... |
Arguments passed on to |
note |
A string that is printed above the |
return |
Logical - should df be returned? |
The original dataframe, unless return
is set to FALSE. In that
case, NULL is returned invisibly, so that the function can be used to just
add a note above the output of another function.
Inspired by the magrittr %T>%
operator that promises similar
functionality but often didn't quite fit my needs
library(magrittr) x <- 1:5 %>% tunnel(mean, note = "Mean") %>% tunnel(sd, note = "SD") x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.