knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
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:
mutate...
, summarise...
etc.remotes::install_github("milesmcbain/wisegroup")
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:
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:
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
still_grouped <- flights %>% group_by(year, month, day) %>% summarise...(max_delay = max(dep_delay, na.rm = TRUE)) still_grouped
and with mutate:
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
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.
If there's a function you think should be included make a PR for "./group_aware_functions.R"!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.