Debian Codegraph @

R/dplyr.R

raw
1 #' Mutate a skim_df
2 #'
3 #' [dplyr::mutate()] currently drops attributes, but we need to keep them around
4 #' for other skim behaviors. Otherwise the behavior is exactly the same. For
5 #' more information, see <https://github.com/tidyverse/dplyr/issues/3429>.
6 #'
7 #' @param .data A `skim_df`, which behaves like a `tbl.`
8 #' @param ... Name-value pairs of expressions, each with length 1 or the same
9 #' length as the number of rows in the group, if using [dplyr::group_by()], or
10 #' in the entire input (if not using groups). The name of each argument will
11 #' be the name of a new variable, and the value will be its corresponding
12 #' value. Use `NULL` value in [dplyr::mutate()] to drop a variable. New
13 #' variables overwrite existing variables of the same name.
14 #'
15 #' The arguments in `...` are automatically quoted with [rlang::quo()] and
16 #' evaluated with [rlang::eval_tidy()] in the context of the data frame. They
17 #' support unquoting [rlang::quasiquotation] and splicing. See
18 #' `vignette("programming", package = "dplyr")` for an introduction to these
19 #' concepts.
20 #' @return A `skim_df` object, which also inherits the class(es) of the input
21 #' data. In many ways, the object behaves like a [tibble::tibble()].
22 #' @seealso [dplyr::mutate()] for the function's expected behavior.
23 #' @importFrom dplyr mutate
24 #' @export
25 mutate.skim_df <- function(.data, ...) {
26 mutated <- NextMethod("mutate")
27 if (could_be_skim_df(mutated)) {
28 reassign_skim_attrs(mutated, .data)
29 } else {
30 strip_skim_attrs(mutated)
31 }
32 }