R/retbl.R

Defines functions retbl_rowwise retbl_peel retbl_drop retbl

Documented in retbl retbl_drop retbl_peel retbl_rowwise

#' Re-tibble by group
#'
#' Use the superpowered [dplyr::summarise()] with explicit
#' grouping.
#'
#' @inheritParams dplyr::summarise
#'
#' @export
#'
#' @examples
#' library(dplyr, warn.conflicts = FALSE)
#'
#' # default keeps grouping after sumr
#' starwars %>%
#'   group_by(species) %>%
#'   retbl(film = unique(unlist(films)))
#'
retbl <- function(.data, ...) {
  dplyr::summarise(.data, ..., .groups = "keep")
}

#' @rdname retbl
#' @export
retbl_drop <- function(.data, ...) {
  dplyr::summarise(.data, ..., .groups = "drop")
}

#' @rdname retbl
#' @export
retbl_peel <- function(.data, ...) {
  dplyr::summarise(.data, ..., .groups = "drop_last")
}

#' @rdname retbl
#' @export
retbl_rowwise <- function(.data, ...) {
  dplyr::summarise(.data, ..., .groups = "rowwise")
}
paleolimbot/sumr documentation built on Dec. 31, 2020, 1:13 a.m.