Group-wise modification of data and complex operations
Source:R/dtrackr.R
group_modify.trackr_df.Rd
Group modifying a data set acts in the normal way. The internal mechanics of
the modify function are opaque to the history. This means these can be used
to wrap any unsupported operation without losing the history (e.g. df %>% track() %>% group_modify(function(d,...) { d %>% unsupported_operation() })
) Prior to the operation the size of the group is calculated {.count.in}
and after the operation the output size {.count.out} The group {.strata}
is also available (if grouped) for reporting See dplyr::group_modify()
.
Usage
# S3 method for class 'trackr_df'
group_modify(
.data,
...,
.messages = NULL,
.headline = .defaultHeadline(),
.type = "modify",
.tag = NULL
)
Arguments
- .data
A grouped tibble
- ...
Additional arguments passed on to
.f
Named arguments passed on todplyr::group_modify
.f
A function or formula to apply to each group.
If a function, it is used as is. It should have at least 2 formal arguments.
If a formula, e.g.
~ head(.x)
, it is converted to a function.In the formula, you can use
.
or.x
to refer to the subset of rows of.tbl
for the given group.y
to refer to the key, a one row tibble with one column per grouping variable that identifies the group
.keep
are the grouping variables kept in
.x
- .messages
a set of glue specs. The glue code can use any global variable, or {.strata},{.count.in},and {.count.out}
- .headline
a headline glue spec. The glue code can use any global variable, or {.strata},{.count.in},and {.count.out}
- .type
default "modify": used to define formatting
- .tag
if you want the summary data from this step in the future then give it a name with .tag.
Examples
library(dplyr)
library(dtrackr)
tmp = iris %>% track() %>% group_by(Species)
tmp %>% group_modify(
function(d,g,...) { return(tibble::tibble(x=runif(10))) },
.messages="{.count.in} in, {.count.out} out"
) %>% history()
#> dtrackr history:
#> number of flowchart steps: 3 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> ├ [Species:setosa]: "Species:setosa", "50 in, 10 out"
#> ├ [Species:versicolor]: "Species:versicolor", "50 in, 10 out"
#> └ [Species:virginica]: "Species:virginica", "50 in, 10 out"