grp: Pass grouping definitions into functions

View source: R/utils.R

grpR Documentation

Pass grouping definitions into functions

Description

Inspired by dplyr::vars(), but converting strings to symbols and auto names all arguments

Usage

grp(...)

Arguments

...

Variables to group by. These arguments are automatically quoted and later evaluated in the context of the data frame. They support unquoting.

Value

named list containing quosures or symbols

Examples

fn <- rOstluft.data::f("Zch_Stampfenbachstrasse_d1_2017.csv")
data <- rOstluft::read_airmo_csv(fn)

# adding group_nest to quickly glance over the groups
groupby <- function(df, group = grp()) {
  dplyr::group_by(df, !!!group) %>%
    dplyr::group_nest()
}

# no grouping -> everything will be nested
groupby(data)

# use a symbol, string or an expression
groupby(data, grp(site, "unit", lubridate::year(starttime)))

# autonaming works fine with strings and symbols, but for expressions
# it probably a good idea to provide a name:
groupby(data, grp(site, year = lubridate::year(starttime)))

Ostluft/rOstluft.plot documentation built on Jan. 26, 2025, 1:05 a.m.