R: Get counts of types of mapped side effects.

tally {collateral} | R Documentation

## Get counts of types of mapped side effects.

### Description

Unlike `summary`, the tally functions return counts of individual types of side effects. This makes them easy to use with `summarise`.

### Usage

    tally_results(x)

    tally_errors(x)

    tally_warnings(x)

    tally_messages(x)

    tally_output(x)

### Arguments

`x` | A `safely_mapped` or `quietly_mapped` list to tally.

### Details

Importantly, the `tally` functions tell you how many elements returned a type of side effect, not the number of those side effects. Some list elements might return more than one warning, for example, and these are not counted separately.

### Value

An integer vector of length 1.

### Examples

    library(magrittr)

    list("a", 10, 100) %>% map_safely(log) %>% tally_errors()
    list(5, -12, 103) %>% map_quietly(log) %>% tally_warnings()

    suppressMessages(library(tidyverse))

    # if you're working with list-columns, the tally functions are useful
    # in conjunction with dplyr::summarise()
    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))) %>%
      summarise(
        num_results = tally_results(qlog),
        num_warnings = tally_warnings(qlog))

[Package collateral version 0.4.2 Index]