diff --git a/NAMESPACE b/NAMESPACE index 26588286f..26f77abd9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,8 @@ # Generated by roxygen2: do not edit by hand +S3method(build_longer_spec,data.frame) +S3method(build_wider_spec,data.frame) +S3method(chop,data.frame) S3method(complete,data.frame) S3method(complete_,data.frame) S3method(drop_na,data.frame) @@ -16,13 +19,17 @@ S3method(full_seq,POSIXct) S3method(full_seq,numeric) S3method(gather,data.frame) S3method(gather_,data.frame) +S3method(hoist,data.frame) S3method(nest,data.frame) S3method(nest,grouped_df) S3method(nest,tbl_df) S3method(nest_legacy,data.frame) S3method(nest_legacy,tbl_df) +S3method(pack,data.frame) S3method(pivot_longer,data.frame) +S3method(pivot_longer_spec,data.frame) S3method(pivot_wider,data.frame) +S3method(pivot_wider_spec,data.frame) S3method(replace_na,data.frame) S3method(replace_na,default) S3method(separate,data.frame) @@ -31,11 +38,16 @@ S3method(separate_rows,data.frame) S3method(separate_rows_,data.frame) S3method(spread,data.frame) S3method(spread_,data.frame) +S3method(unchop,data.frame) +S3method(uncount,data.frame) S3method(unite,data.frame) S3method(unite_,data.frame) S3method(unnest,data.frame) S3method(unnest,rowwise_df) S3method(unnest_legacy,data.frame) +S3method(unnest_longer,data.frame) +S3method(unnest_wider,data.frame) +S3method(unpack,data.frame) export("%>%") export(as_tibble) export(build_longer_spec) diff --git a/R/chop.R b/R/chop.R index ed235f12b..e47084ebf 100644 --- a/R/chop.R +++ b/R/chop.R @@ -40,6 +40,7 @@ #' @param ptype Optionally, supply a data frame prototype for the output `cols`, #' overriding the default that will be guessed from the combination of #' individual values. +#' @param ... Additional arguments passed on to methods. #' @export #' @examples #' # Chop ============================================================== @@ -66,7 +67,13 @@ #' df <- tibble(x = 1:3, y = list(NULL, tibble(x = 1), tibble(y = 1:2))) #' df %>% unchop(y) #' df %>% unchop(y, keep_empty = TRUE) -chop <- function(data, cols) { +chop <- function(data, cols, ...) { + ellipsis::check_dots_used() + UseMethod("chop") +} + +#' @export +chop.data.frame <- function(data, cols, ...) { if (missing(cols)) { return(data) } @@ -89,7 +96,13 @@ chop <- function(data, cols) { #' @export #' @rdname chop -unchop <- function(data, cols, keep_empty = FALSE, ptype = NULL) { +unchop <- function(data, cols, ..., keep_empty = FALSE, ptype = NULL) { + ellipsis::check_dots_used() + UseMethod("unchop") +} + +#' @export +unchop.data.frame <- function(data, cols, ..., keep_empty = FALSE, ptype = NULL) { cols <- tidyselect::eval_select(enquo(cols), data) if (length(cols) == 0) { return(data) diff --git a/R/pack.R b/R/pack.R index 3dab13b7d..418b27625 100644 --- a/R/pack.R +++ b/R/pack.R @@ -60,6 +60,11 @@ #' df %>% unpack(c(y, z)) #' df %>% unpack(c(y, z), names_sep = "_") pack <- function(.data, ..., .names_sep = NULL) { + UseMethod("pack") +} + +#' @export +pack.data.frame <- function(.data, ..., .names_sep = NULL) { cols <- enquos(...) if (any(names2(cols) == "")) { abort("All elements of `...` must be named") @@ -94,7 +99,13 @@ pack <- function(.data, ..., .names_sep = NULL) { #' #' See [vctrs::vec_as_names()] for more details on these terms and the #' strategies used to enforce them. -unpack <- function(data, cols, names_sep = NULL, names_repair = "check_unique") { +unpack <- function(data, cols, ..., names_sep = NULL, names_repair = "check_unique") { + ellipsis::check_dots_used() + UseMethod("unpack") +} + +#' @export +unpack.data.frame <- function(data, cols, ..., names_sep = NULL, names_repair = "check_unique") { check_present(cols) cols <- tidyselect::eval_select(enquo(cols), data) diff --git a/R/pivot-long.R b/R/pivot-long.R index 62fafbc1f..fd31dee62 100644 --- a/R/pivot-long.R +++ b/R/pivot-long.R @@ -207,8 +207,22 @@ pivot_longer_spec <- function(data, names_repair = "check_unique", values_drop_na = FALSE, values_ptypes = list(), - values_transform = list() + values_transform = list(), + ... ) { + ellipsis::check_dots_used() + UseMethod("pivot_longer_spec") +} + +#' @export +pivot_longer_spec.data.frame <- function(data, + spec, + ..., + names_repair = "check_unique", + values_drop_na = FALSE, + values_ptypes = list(), + values_transform = list() + ) { spec <- check_spec(spec) spec <- deduplicate_spec(spec, data) @@ -265,6 +279,7 @@ pivot_longer_spec <- function(data, #' @rdname pivot_longer_spec #' @export build_longer_spec <- function(data, cols, + ..., names_to = "name", values_to = "value", names_prefix = NULL, @@ -272,6 +287,20 @@ build_longer_spec <- function(data, cols, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL) { + ellipsis::check_dots_used() + UseMethod("build_longer_spec") +} + +#' @export +build_longer_spec.data.frame <- function(data, cols, + ..., + names_to = "name", + values_to = "value", + names_prefix = NULL, + names_sep = NULL, + names_pattern = NULL, + names_ptypes = NULL, + names_transform = NULL) { cols <- tidyselect::eval_select(enquo(cols), data[unique(names(data))]) if (length(cols) == 0) { diff --git a/R/pivot-wide.R b/R/pivot-wide.R index 421f5dc88..38e86f785 100644 --- a/R/pivot-wide.R +++ b/R/pivot-wide.R @@ -109,6 +109,7 @@ pivot_wider <- function(data, #' @export pivot_wider.data.frame <- function(data, + ..., id_cols = NULL, names_from = name, names_prefix = "", @@ -118,8 +119,7 @@ pivot_wider.data.frame <- function(data, names_repair = "check_unique", values_from = value, values_fill = NULL, - values_fn = NULL, - ... + values_fn = NULL ) { names_from <- enquo(names_from) values_from <- enquo(values_from) @@ -133,7 +133,8 @@ pivot_wider.data.frame <- function(data, ) id_cols <- enquo(id_cols) - pivot_wider_spec(data, spec, !!id_cols, + pivot_wider_spec(data, spec, + id_cols = !!id_cols, names_repair = names_repair, values_fill = values_fill, values_fn = values_fn @@ -186,11 +187,24 @@ pivot_wider.data.frame <- function(data, #' us_rent_income %>% #' pivot_wider_spec(spec2) pivot_wider_spec <- function(data, - spec, - names_repair = "check_unique", - id_cols = NULL, - values_fill = NULL, - values_fn = NULL) { + spec, + ..., + names_repair = "check_unique", + id_cols = NULL, + values_fill = NULL, + values_fn = NULL) { + ellipsis::check_dots_used() + UseMethod("pivot_wider_spec") +} + +#' @export +pivot_wider_spec.data.frame <- function(data, + spec, + ..., + names_repair = "check_unique", + id_cols = NULL, + values_fill = NULL, + values_fn = NULL) { spec <- check_spec(spec) if (is.function(values_fn)) { @@ -286,11 +300,26 @@ pivot_wider_spec <- function(data, build_wider_spec <- function(data, names_from = name, values_from = value, + ..., names_prefix = "", names_sep = "_", names_glue = NULL, names_sort = FALSE ) { + ellipsis::check_dots_used() + UseMethod("build_wider_spec") +} + +#' @export +build_wider_spec.data.frame <- function(data, + names_from = name, + values_from = value, + ..., + names_prefix = "", + names_sep = "_", + names_glue = NULL, + names_sort = FALSE + ) { names_from <- tidyselect::eval_select(enquo(names_from), data) values_from <- tidyselect::eval_select(enquo(values_from), data) diff --git a/R/rectangle.R b/R/rectangle.R index 2f450c367..8fa10a92d 100644 --- a/R/rectangle.R +++ b/R/rectangle.R @@ -115,6 +115,11 @@ #' #' @export hoist hoist <- function(.data, .col, ..., .remove = TRUE, .simplify = TRUE, .ptype = list(), .transform = list()) { + UseMethod("hoist") +} + +#' @export +hoist.data.frame <- function(.data, .col, ..., .remove = TRUE, .simplify = TRUE, .ptype = list(), .transform = list()) { check_present(.col) .col <- tidyselect::vars_pull(names(.data), !!enquo(.col)) x <- .data[[.col]] @@ -195,6 +200,7 @@ check_pluckers <- function(...) { #' has inner names. #' @inheritParams unnest unnest_longer <- function(data, col, + ..., values_to = NULL, indices_to = NULL, indices_include = NULL, @@ -203,6 +209,21 @@ unnest_longer <- function(data, col, ptype = list(), transform = list() ) { + ellipsis::check_dots_used() + UseMethod("unnest_longer") +} + +#' @export +unnest_longer.data.frame <- function(data, col, + ..., + values_to = NULL, + indices_to = NULL, + indices_include = NULL, + names_repair = "check_unique", + simplify = TRUE, + ptype = list(), + transform = list() + ) { check_present(col) col <- tidyselect::vars_pull(names(data), !!enquo(col)) @@ -243,12 +264,26 @@ unnest_longer <- function(data, col, #' as is. If a string, the inner and outer names will be paste together using #' `names_sep` as a separator. unnest_wider <- function(data, col, + ..., names_sep = NULL, simplify = TRUE, names_repair = "check_unique", ptype = list(), transform = list() ) { + ellipsis::check_dots_used() + UseMethod("unnest_wider") +} + +#' @export +unnest_wider.data.frame <- function(data, col, + ..., + names_sep = NULL, + simplify = TRUE, + names_repair = "check_unique", + ptype = list(), + transform = list() + ) { check_present(col) col <- tidyselect::vars_pull(tbl_vars(data), !!enquo(col)) diff --git a/R/uncount.R b/R/uncount.R index 29ab067a3..f34e112bd 100644 --- a/R/uncount.R +++ b/R/uncount.R @@ -10,6 +10,7 @@ #' identifier for each created row. #' @param .remove If `TRUE`, and `weights` is the name of a column in `data`, #' then this column is removed. +#' @param ... Additional arguments passed on to methods. #' @export #' @examples #' df <- tibble(x = c("a", "b"), n = c(1, 2)) @@ -21,7 +22,13 @@ #' #' # Or expressions #' uncount(df, 2 / n) -uncount <- function(data, weights, .remove = TRUE, .id = NULL) { +uncount <- function(data, weights, ..., .remove = TRUE, .id = NULL) { + ellipsis::check_dots_used() + UseMethod("uncount") +} + +#' @export +uncount.data.frame <- function(data, weights, ..., .remove = TRUE, .id = NULL) { weights_quo <- enquo(weights) w <- dplyr::pull(dplyr::mutate(data, `_weight` = !! weights_quo)) # NOTE `vec_cast()` and check for positive weights can be removed diff --git a/man/chop.Rd b/man/chop.Rd index 9ebf59861..798dc53e5 100644 --- a/man/chop.Rd +++ b/man/chop.Rd @@ -5,9 +5,9 @@ \alias{unchop} \title{Chop and unchop} \usage{ -chop(data, cols) +chop(data, cols, ...) -unchop(data, cols, keep_empty = FALSE, ptype = NULL) +unchop(data, cols, ..., keep_empty = FALSE, ptype = NULL) } \arguments{ \item{data}{A data frame.} @@ -19,6 +19,8 @@ For \code{unchop()}, each column should be a list-column containing generalised vectors (e.g. any mix of \code{NULL}s, atomic vector, S3 vectors, a lists, or data frames).} +\item{...}{Additional arguments passed on to methods.} + \item{keep_empty}{By default, you get one row of output for each element of the list your unchopping/unnesting. This means that if there's a size-0 element (like \code{NULL} or an empty data frame), that entire row diff --git a/man/hoist.Rd b/man/hoist.Rd index deb35059f..013fa5e74 100644 --- a/man/hoist.Rd +++ b/man/hoist.Rd @@ -20,6 +20,7 @@ hoist( unnest_longer( data, col, + ..., values_to = NULL, indices_to = NULL, indices_include = NULL, @@ -32,6 +33,7 @@ unnest_longer( unnest_wider( data, col, + ..., names_sep = NULL, simplify = TRUE, names_repair = "check_unique", diff --git a/man/pack.Rd b/man/pack.Rd index 6950f12d4..a5fce8b8e 100644 --- a/man/pack.Rd +++ b/man/pack.Rd @@ -7,7 +7,7 @@ \usage{ pack(.data, ..., .names_sep = NULL) -unpack(data, cols, names_sep = NULL, names_repair = "check_unique") +unpack(data, cols, ..., names_sep = NULL, names_repair = "check_unique") } \arguments{ \item{...}{<\code{\link[=tidyr_tidy_select]{tidy-select}}> Columns to pack, specified diff --git a/man/pivot_longer_spec.Rd b/man/pivot_longer_spec.Rd index 6a3f53bde..84647374f 100644 --- a/man/pivot_longer_spec.Rd +++ b/man/pivot_longer_spec.Rd @@ -11,12 +11,14 @@ pivot_longer_spec( names_repair = "check_unique", values_drop_na = FALSE, values_ptypes = list(), - values_transform = list() + values_transform = list(), + ... ) build_longer_spec( data, cols, + ..., names_to = "name", values_to = "value", names_prefix = NULL, @@ -68,6 +70,8 @@ If not specified, the type of the columns generated from \code{names_to} will be character, and the type of the variables generated from \code{values_to} will be the common type of the input columns used to generate them.} +\item{...}{Additional arguments passed on to methods.} + \item{cols}{<\code{\link[=tidyr_tidy_select]{tidy-select}}> Columns to pivot into longer format.} diff --git a/man/pivot_wider_spec.Rd b/man/pivot_wider_spec.Rd index b7f2cfd02..991a35d67 100644 --- a/man/pivot_wider_spec.Rd +++ b/man/pivot_wider_spec.Rd @@ -8,6 +8,7 @@ pivot_wider_spec( data, spec, + ..., names_repair = "check_unique", id_cols = NULL, values_fill = NULL, @@ -18,6 +19,7 @@ build_wider_spec( data, names_from = name, values_from = value, + ..., names_prefix = "", names_sep = "_", names_glue = NULL, @@ -38,6 +40,8 @@ pivoted from the wide format. The special \code{.seq} variable is used to disambiguate rows internally; it is automatically removed after pivotting.} +\item{...}{Additional arguments passed on to methods.} + \item{names_repair}{What happens if the output has invalid column names? The default, \code{"check_unique"} is to error if the columns are duplicated. Use \code{"minimal"} to allow duplicates in the output, or \code{"unique"} to diff --git a/man/uncount.Rd b/man/uncount.Rd index 4ea97eb93..459d9f1bf 100644 --- a/man/uncount.Rd +++ b/man/uncount.Rd @@ -4,7 +4,7 @@ \alias{uncount} \title{"Uncount" a data frame} \usage{ -uncount(data, weights, .remove = TRUE, .id = NULL) +uncount(data, weights, ..., .remove = TRUE, .id = NULL) } \arguments{ \item{data}{A data frame, tibble, or grouped tibble.} @@ -12,6 +12,8 @@ uncount(data, weights, .remove = TRUE, .id = NULL) \item{weights}{A vector of weights. Evaluated in the context of \code{data}; supports quasiquotation.} +\item{...}{Additional arguments passed on to methods.} + \item{.remove}{If \code{TRUE}, and \code{weights} is the name of a column in \code{data}, then this column is removed.}