R/transmute.R

Defines functions transmute. transmute

Documented in transmute transmute.

#' Add new variables and drop all others
#'
#' @description
#' Unlike `mutate()`, `transmute()` keeps only the variables that you create
#'
#' @param .df A data.frame or data.table
#' @param ... Columns to create/modify
#' @param .by Columns to group by
#'
#' @export
#'
#' @examples
#' df <- data.table(
#'   a = 1:3,
#'   b = 4:6,
#'   c = c("a", "a", "b")
#' )
#'
#' df %>%
#'   transmute(double_a = a * 2)
transmute <- function(.df, ..., .by = NULL) {
  mutate(.df, ..., .by = {{ .by }}, .keep = "none")
}

#' @export
#' @keywords internal
#' @inherit transmute
transmute. <- function(.df, ..., .by = NULL) {
  deprecate_dot_fun()
  transmute(.df, ..., .by = {{ .by }})
}

Try the tidytable package in your browser

Any scripts or data that you put into this service are public.

tidytable documentation built on Oct. 5, 2023, 5:07 p.m.