Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/MilesMcBain/wisegroup

Now I am become death, destroyer of groups....
https://github.com/MilesMcBain/wisegroup

Last synced: 9 days ago
JSON representation

Now I am become death, destroyer of groups....

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# wisegroup

[![Travis build status](https://travis-ci.org/milesmcbain/wisegroup.svg?branch=master)](https://travis-ci.org/milesmcbain/wisegroup)

> Now I am become death, destroyer of groups....

Never be burned by forgetting to `ungroup()` again.

This packages contains alternative versions of common group-aware `tidyverse` functions that either:

* automatically ungroup the returned data OR
* allow the developer to make explicit that groups are being carried forward, signalling the potential for group related errors with a '...' variant of the orignal function, e.g. `mutate...`, `summarise...` etc.

## Installation

```{r, eval = FALSE}
remotes::install_github("milesmcbain/wisegroup")
```

## Usage

`wisegroup` is designed to mask `tidyverse` functions in your global
environment. It is recommended that you use this package in conjunction with
`conflicted`. This means that the order of the `library` calls will not matter,
and that the masking is made explicit like so:

```{r}

library(conflicted)
library(wisegroup)
library(tidyverse)
library(nycflights13)

conflict_prefer("summarise", "wisegroup")
conflict_prefer("mutate", "wisegroup")

```

Just be lazy. `conflicted` will let you know when you need to disambiguate.

So now you have automatically dropped groups after summarising over
multiple grouping columns:

```{r}

grouped_no_more <-
flights %>%
group_by(year, month, day) %>%
summarise(max_delay = max(dep_delay, na.rm = TRUE))

grouped_no_more

```

You indicate the grouping is sticking around with the `...` suffix

```{r}

still_grouped <-
flights %>%
group_by(year, month, day) %>%
summarise...(max_delay = max(dep_delay, na.rm = TRUE))

still_grouped

```

and with mutate:

```{r}

summarised_over_mutates_groups <-
flights %>%
group_by(year, month, day) %>%
mutate...(day_dep_variance = var(dep_delay, na.rm = TRUE)) %>%
summarise(max_var = max(day_dep_variance))

summarised_over_mutates_groups

```

## Fun Fact

This package generates its own source and documentation, so that adding new
wrappers is low effort.

To generate new wrappers, an entry is added to
"./group_aware_functions.R" and "./make.R" is run.

## Contributing

If there's a function you think should be included make a PR for "./group_aware_functions.R"!