library(dplyr)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

sumr

Lifecycle: experimental

The goal of sumr is to provide a workaround for the noisy and permissive dplyr::summarise(). It's seriously awesome and powerful! But you can get burned if you did not expect this behaviour.

library(dplyr)
starwars %>%
  group_by(species) %>%
  summarise(mass = mean(mass)) %>% 
  count(species)

starwars %>%
  group_by(species) %>% 
  summarise(films = unique(unlist(films))) %>% 
  count(species)

You can silence this message using options(dplyr.summarise.inform = FALSE). If you'd rather not write this at the top of every script, you can use this package to make the grouping of your result explicit with roughly the same number of characters:

library(sumr)

# drops grouping
starwars %>%
  group_by(species) %>%
  sumr(mass = mean(mass))

# peels back one layer of grouping per call
starwars %>%
  group_by(gender, species) %>%
  sumr_peel(mass = mean(mass, na.rm = TRUE)) %>%
  sumr_peel(mass = mean(mass, na.rm = TRUE))

# keeps current grouping
starwars %>%
  group_by(species) %>%
  sumr_keep(mass = mean(mass))

sumr() checks for length-one results, but you can use retbl() to use the awesome new features of summarise(). Because retbl() typically computes a new data frame for each group, groups are kept:

starwars %>%
  group_by(species) %>% 
  retbl(films = unique(unlist(films)))

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("paleolimbot/sumr")


paleolimbot/sumr documentation built on Dec. 31, 2020, 1:13 a.m.