Map functions while capturing results, errors, warnings, messages and other output tidily, then filter and summarise data frames or lists on the basis of those side effects.
Automatically map complex operations
quietly, and quickly see the captured side effects.
collateral package extends the power of
purrr::quietly(), providing variants of
map_quietly()—that automatically apply the appropriate function wrapper and print the resulting output nicely.
This is especially useful for tidy workflows: you can
nest() a data frame, apply a complex operation (such as building a regression model or building and saving a plot) to each group and quickly see which groups need to be inspected in more detail:
We'll submit to CRAN soon, but for now, use
devtools to install
library(tidyverse)library(collateral)test =# tidy up and trim down for the examplemtcars %>%rownames_to_column(var = "car") %>%as_data_frame() %>%select(car, cyl, disp, wt) %>%# spike some rows in cyl == 4 to make them failmutate(wt = dplyr::case_when(wt < 2 ~ -wt,TRUE ~ wt)) %>%# nest and do some operations quietly()nest(-cyl) %>%mutate(qlog = map_quietly(data, ~ log(.$wt)))test#> # A tibble: 3 x 4#> cyl data qlog#> <dbl> <list> <collat>#> 1 6 <tibble [7 x 3]> R O _ _#> 2 4 <tibble [11 x 3]> R O _ W#> 3 8 <tibble [14 x 3]> R O _ _
pillar to style output, so supported terminals will also color the output! Properly styling knitted output is still on the to-do list, though.
If you're a fan of iterating over two or more inputs in lockstep, then
pmap() variants are also provided:
collateral also provides
has_() functions to help you filter or summarise
your side effects, as well as a
summary() mehod. If you haven't used a list-column workflow before, take a look at the vignette to see how it's done!
NEWS.mdfile to track changes to the package.
has_*()functions for use with
tally_*()functions to use
summary()methods to use
tally_*()functions for use with
summary()methods to report the count of types of side effects in a column.