Giter Club home page Giter Club logo

collateral's Introduction

collateral

Map complex operations safely or quietly, quickly see the captured side effectsand quickly spot and isolate captured side effects.

The collateral package extends the power of purrr's side effect-capturing functions, giving you:

  • drop-in map() variants, allowing you to capture side effects from functions mapped over lists, vectors and list-columns;
  • fancy tibble output, allowing you to see which rows delivered errors or side effects; and
  • helpers for summarising side effects or filtering tibbles and lists for present side effects.

If you're not familiar with purrr or haven't used a list-column workflow in R before, the collateral vignette shows you how it works, the benefits for your analysis and how collateral simplifies the process of handling complex mapped operations.

If you're already familiar with purrr, the tl;dr is that collateral::map_safely() and collateral::map_quietly() (and their map2 and pmap variants) will automatically wrap your supplied function in safely() or quietly() and will provide enhanced print()ed output and tibble displays. You can then use the has_*() and tally_*() functions to filter or summarise the returned tibbles or lists.

Installation

You can install collateral on CRAN:

install.packages('collateral')

Or install the development version using devtools:

devtools::install_github('rensa/collateral')

Example

library(tidyverse)
library(collateral)

test =
  # tidy up and trim down for the example
  mtcars %>%
  rownames_to_column(var = "car") %>%
  as_data_frame() %>%
  select(car, cyl, disp, wt) %>%
  # spike some rows in cyl == 4 to make them fail
  mutate(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 _ _

Example of styled collateral output

collateral uses pillar to style output, so supported terminals will also color the output!

Support

If you have a problem with collateral, please don't hesitate to file an issue or contact me!

collateral's People

Contributors

jimjam-slam avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.