doo: Alternative to dplyr::do for doing anything

dooR Documentation

Alternative to dplyr::do for doing anything

Description

Provides an alternative to the dplyr:do() using nest(), mutate() and map() to apply a function to a grouped data frame.

Usage

doo(.data, .fun, ..., unnest = TRUE)

Arguments

.data

a (grouped) data frame

.fun

A function, formula, or atomic vector.

...

Additional arguments passed on to .fun

unnest

Logical argument defaults to TRUE to control if results of .fun should be unnested. Valid only if the result is of class data.frame or tbl_df.

Details

If the applied function returns a data frame, then the output will be automatically unnested. Otherwise, the output includes the grouping variables and a column named "data" , which is a "list-columns" containing the results for group combinations.

Value

a data frame

Author(s)

Tiago Olivoto tiagoolivoto@gmail.com

Examples


library(metan)
# Head the first two lines of each environment
data_ge2 %>%
 group_by(ENV) %>%
 doo(~head(., 2))

# Genotype analysis for each environment using 'gafem()'
# variable PH
data_ge2 %>%
  group_by(ENV) %>%
  doo(~gafem(., GEN, REP, PH, verbose = FALSE))


metan documentation built on March 7, 2023, 5:34 p.m.