forked from tidyverse/dplyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup-indices.R
35 lines (31 loc) · 869 Bytes
/
group-indices.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#' Group id.
#'
#' Generate a unique id for each group
#'
#' @seealso \code{\link{group_by}}
#' @param .data a tbl
#' @inheritParams group_by
#' @inheritParams filter
#' @export
#' @examples
#' group_indices(mtcars, cyl)
group_indices <- function(.data, ...) {
group_indices_(.data, .dots = lazyeval::lazy_dots(...) )
}
#' @export
#' @rdname group_indices
group_indices_ <- function(.data, ..., .dots) {
UseMethod("group_indices_")
}
#' @export
group_indices_.data.frame <- function(.data, ..., .dots ){
groups <- group_by_prepare(.data, .dots = .dots )
grouped_indices_impl(groups$data, groups$groups)
}
#' @export
group_indices_.grouped_df <- function(.data, ..., .dots ){
if( length(list(...)) || ( ! missing(.dots) && length(.dots) ) ){
warning( "group_indices_.grouped_df ignores extra arguments" )
}
grouped_indices_grouped_df_impl(.data)
}