From 01e33bec3d99354da5072c8f721a3b85ecd056a0 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:04:34 +0000 Subject: [PATCH 01/13] make `pivot_wider_spec()` and `build_wider_spec()` generic --- R/pivot-wide.R | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/R/pivot-wide.R b/R/pivot-wide.R index 421f5dc88..a135884f3 100644 --- a/R/pivot-wide.R +++ b/R/pivot-wide.R @@ -186,11 +186,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)) { @@ -289,8 +302,22 @@ build_wider_spec <- function(data, names_prefix = "", names_sep = "_", names_glue = NULL, - names_sort = FALSE + 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) From e1a8e480aa8c77db69b2294e95330eec49fcf33f Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:07:36 +0000 Subject: [PATCH 02/13] make `pivot_longer_spec()` and `build_longer_spec()` generic --- R/pivot-long.R | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/R/pivot-long.R b/R/pivot-long.R index 62fafbc1f..ad94f08dc 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) @@ -271,7 +285,22 @@ build_longer_spec <- function(data, cols, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, - names_transform = NULL) { + names_transform = NULL, + ...) { + ellipsis::check_dots_used() + UseMethod("build_longer_spec") +} + +#' @export +build_longer_spec <- 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) { From f0f9ab04f156f9895b18a7610f625258ab4f9f97 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:10:26 +0000 Subject: [PATCH 03/13] add missing dots to `build_wider_spec.data.frame()` --- R/pivot-long.R | 18 +++++++++--------- R/pivot-wide.R | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/R/pivot-long.R b/R/pivot-long.R index ad94f08dc..1173c5652 100644 --- a/R/pivot-long.R +++ b/R/pivot-long.R @@ -292,15 +292,15 @@ build_longer_spec <- function(data, cols, } #' @export -build_longer_spec <- function(data, cols, - names_to = "name", - values_to = "value", - names_prefix = NULL, - names_sep = NULL, - names_pattern = NULL, - names_ptypes = NULL, - names_transform = NULL, - ...) { +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 a135884f3..1535b3eba 100644 --- a/R/pivot-wide.R +++ b/R/pivot-wide.R @@ -316,7 +316,8 @@ build_wider_spec.data.frame <- function(data, names_prefix = "", names_sep = "_", names_glue = NULL, - names_sort = FALSE + names_sort = FALSE, + ... ) { names_from <- tidyselect::eval_select(enquo(names_from), data) values_from <- tidyselect::eval_select(enquo(values_from), data) From adbf9bc6cdf7b0c466b99302f30662142b84387b Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:12:07 +0000 Subject: [PATCH 04/13] make `uncount()` generic --- R/uncount.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/uncount.R b/R/uncount.R index 29ab067a3..91c6c2445 100644 --- a/R/uncount.R +++ b/R/uncount.R @@ -21,7 +21,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 From 5682209425589d3d56aeb88ad1c092146e6e269e Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:14:42 +0000 Subject: [PATCH 05/13] make `unnest_longer()` and `unnest_wider()` generic --- R/rectangle.R | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/R/rectangle.R b/R/rectangle.R index 2f450c367..7ec84afd9 100644 --- a/R/rectangle.R +++ b/R/rectangle.R @@ -201,8 +201,24 @@ unnest_longer <- function(data, col, names_repair = "check_unique", simplify = TRUE, ptype = list(), - transform = 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)) @@ -247,8 +263,22 @@ unnest_wider <- function(data, col, simplify = TRUE, names_repair = "check_unique", ptype = list(), - transform = 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)) From 91c07daeeebcd2113a60906f1cb2f3cf7da62884 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:18:48 +0000 Subject: [PATCH 06/13] make `hoist()` generic --- R/rectangle.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/rectangle.R b/R/rectangle.R index 7ec84afd9..61f60b3dd 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]] From 72e09c8782d558523be46b1e7fc90846a107d032 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:19:19 +0000 Subject: [PATCH 07/13] document() --- NAMESPACE | 8 ++++++++ man/hoist.Rd | 6 ++++-- man/pivot_longer_spec.Rd | 8 ++++++-- man/pivot_wider_spec.Rd | 8 ++++++-- man/uncount.Rd | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 26588286f..bb9b90d2f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,7 @@ # Generated by roxygen2: do not edit by hand +S3method(build_longer_spec,data.frame) +S3method(build_wider_spec,data.frame) S3method(complete,data.frame) S3method(complete_,data.frame) S3method(drop_na,data.frame) @@ -16,13 +18,16 @@ 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(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 +36,14 @@ S3method(separate_rows,data.frame) S3method(separate_rows_,data.frame) S3method(spread,data.frame) S3method(spread_,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) export("%>%") export(as_tibble) export(build_longer_spec) diff --git a/man/hoist.Rd b/man/hoist.Rd index deb35059f..1d02d9593 100644 --- a/man/hoist.Rd +++ b/man/hoist.Rd @@ -26,7 +26,8 @@ unnest_longer( names_repair = "check_unique", simplify = TRUE, ptype = list(), - transform = list() + transform = list(), + ... ) unnest_wider( @@ -36,7 +37,8 @@ unnest_wider( simplify = TRUE, names_repair = "check_unique", ptype = list(), - transform = list() + transform = list(), + ... ) unnest_auto(data, col) diff --git a/man/pivot_longer_spec.Rd b/man/pivot_longer_spec.Rd index 6a3f53bde..15f988518 100644 --- a/man/pivot_longer_spec.Rd +++ b/man/pivot_longer_spec.Rd @@ -11,7 +11,8 @@ pivot_longer_spec( names_repair = "check_unique", values_drop_na = FALSE, values_ptypes = list(), - values_transform = list() + values_transform = list(), + ... ) build_longer_spec( @@ -23,7 +24,8 @@ build_longer_spec( names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, - names_transform = NULL + names_transform = NULL, + ... ) } \arguments{ @@ -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..afc6ca1d2 100644 --- a/man/pivot_wider_spec.Rd +++ b/man/pivot_wider_spec.Rd @@ -11,7 +11,8 @@ pivot_wider_spec( names_repair = "check_unique", id_cols = NULL, values_fill = NULL, - values_fn = NULL + values_fn = NULL, + ... ) build_wider_spec( @@ -21,7 +22,8 @@ build_wider_spec( names_prefix = "", names_sep = "_", names_glue = NULL, - names_sort = FALSE + names_sort = FALSE, + ... ) } \arguments{ @@ -63,6 +65,8 @@ in the output. You will typically use this when the combination of This can be a named list if you want to apply different aggregations to different value columns.} +\item{...}{Additional arguments passed on to methods.} + \item{names_from}{<\code{\link[=tidyr_tidy_select]{tidy-select}}> A pair of arguments describing which column (or columns) to get the name of the output column (\code{names_from}), and which column (or columns) to get the diff --git a/man/uncount.Rd b/man/uncount.Rd index 4ea97eb93..127cf1819 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.} From 636926c8ca1cf0fa728e9a1cf5a995c41a5c9465 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:23:22 +0000 Subject: [PATCH 08/13] make `chop()` generic --- NAMESPACE | 2 ++ R/chop.R | 16 ++++++++++++++-- man/chop.Rd | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index bb9b90d2f..3a095046a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ 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) @@ -36,6 +37,7 @@ 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) diff --git a/R/chop.R b/R/chop.R index ed235f12b..60f78a653 100644 --- a/R/chop.R +++ b/R/chop.R @@ -66,7 +66,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 +95,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/man/chop.Rd b/man/chop.Rd index 9ebf59861..79d76ad64 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.} From 95da02c53c1780bf51c2890965bbe333e9f220a1 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 10:25:26 +0000 Subject: [PATCH 09/13] make `pack()` and `unpack()` generic --- NAMESPACE | 2 ++ R/pack.R | 13 ++++++++++++- man/pack.Rd | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3a095046a..26f77abd9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,7 @@ 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) @@ -46,6 +47,7 @@ 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/pack.R b/R/pack.R index 3dab13b7d..7e22ea511 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/man/pack.Rd b/man/pack.Rd index 6950f12d4..00e595422 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 From 245a1c19dfdb7293f9a0559522664602a0af231b Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 12:37:45 +0000 Subject: [PATCH 10/13] document dots in `chop()` and `uncount()` --- R/chop.R | 1 + R/uncount.R | 1 + man/chop.Rd | 2 ++ man/uncount.Rd | 2 ++ 4 files changed, 6 insertions(+) diff --git a/R/chop.R b/R/chop.R index 60f78a653..5b99e73da 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 ============================================================== diff --git a/R/uncount.R b/R/uncount.R index 91c6c2445..d2a46ce01 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)) diff --git a/man/chop.Rd b/man/chop.Rd index 79d76ad64..8f78ad1e4 100644 --- a/man/chop.Rd +++ b/man/chop.Rd @@ -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/uncount.Rd b/man/uncount.Rd index 127cf1819..1befe69c8 100644 --- a/man/uncount.Rd +++ b/man/uncount.Rd @@ -17,6 +17,8 @@ then this column is removed.} \item{.id}{Supply a string to create a new variable which gives a unique identifier for each created row.} + +\item{...}{Additional arguments passed on to methods.} } \description{ Performs the opposite operation to \code{\link[dplyr:count]{dplyr::count()}}, duplicating rows From 0e96cf673132eae35415e4cb2e0f0f9f5c2c4b0f Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 12:59:48 +0000 Subject: [PATCH 11/13] move dots in `pivot_*()` functions family --- R/pivot-long.R | 12 ++++++------ R/pivot-wide.R | 23 ++++++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/R/pivot-long.R b/R/pivot-long.R index 1173c5652..fd31dee62 100644 --- a/R/pivot-long.R +++ b/R/pivot-long.R @@ -217,11 +217,11 @@ pivot_longer_spec <- function(data, #' @export pivot_longer_spec.data.frame <- function(data, spec, + ..., names_repair = "check_unique", values_drop_na = FALSE, values_ptypes = list(), - values_transform = list(), - ... + values_transform = list() ) { spec <- check_spec(spec) spec <- deduplicate_spec(spec, data) @@ -279,28 +279,28 @@ pivot_longer_spec.data.frame <- function(data, #' @rdname pivot_longer_spec #' @export build_longer_spec <- function(data, cols, + ..., names_to = "name", values_to = "value", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, - names_transform = 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, - ...) { + 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 1535b3eba..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 @@ -187,11 +188,11 @@ pivot_wider.data.frame <- function(data, #' pivot_wider_spec(spec2) pivot_wider_spec <- function(data, spec, + ..., names_repair = "check_unique", id_cols = NULL, values_fill = NULL, - values_fn = NULL, - ...) { + values_fn = NULL) { ellipsis::check_dots_used() UseMethod("pivot_wider_spec") } @@ -199,11 +200,11 @@ pivot_wider_spec <- function(data, #' @export pivot_wider_spec.data.frame <- function(data, spec, + ..., names_repair = "check_unique", id_cols = NULL, values_fill = NULL, - values_fn = NULL, - ...) { + values_fn = NULL) { spec <- check_spec(spec) if (is.function(values_fn)) { @@ -299,11 +300,11 @@ pivot_wider_spec.data.frame <- function(data, build_wider_spec <- function(data, names_from = name, values_from = value, + ..., names_prefix = "", names_sep = "_", names_glue = NULL, - names_sort = FALSE, - ... + names_sort = FALSE ) { ellipsis::check_dots_used() UseMethod("build_wider_spec") @@ -313,11 +314,11 @@ build_wider_spec <- function(data, build_wider_spec.data.frame <- function(data, names_from = name, values_from = value, + ..., names_prefix = "", names_sep = "_", names_glue = NULL, - names_sort = FALSE, - ... + names_sort = FALSE ) { names_from <- tidyselect::eval_select(enquo(names_from), data) values_from <- tidyselect::eval_select(enquo(values_from), data) From 9e3c5cd4becd827d9a7c7982515cb9ea5ef7dc73 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 13:00:32 +0000 Subject: [PATCH 12/13] move dots in other generics --- R/chop.R | 4 ++-- R/pack.R | 4 ++-- R/rectangle.R | 16 ++++++++-------- R/uncount.R | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/R/chop.R b/R/chop.R index 5b99e73da..e47084ebf 100644 --- a/R/chop.R +++ b/R/chop.R @@ -96,13 +96,13 @@ chop.data.frame <- 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, ...) { +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 7e22ea511..418b27625 100644 --- a/R/pack.R +++ b/R/pack.R @@ -99,13 +99,13 @@ pack.data.frame <- 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", ...) { +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/rectangle.R b/R/rectangle.R index 61f60b3dd..8fa10a92d 100644 --- a/R/rectangle.R +++ b/R/rectangle.R @@ -200,14 +200,14 @@ check_pluckers <- function(...) { #' has inner names. #' @inheritParams unnest unnest_longer <- function(data, col, + ..., values_to = NULL, indices_to = NULL, indices_include = NULL, names_repair = "check_unique", simplify = TRUE, ptype = list(), - transform = list(), - ... + transform = list() ) { ellipsis::check_dots_used() UseMethod("unnest_longer") @@ -215,14 +215,14 @@ unnest_longer <- function(data, col, #' @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(), - ... + transform = list() ) { check_present(col) @@ -264,12 +264,12 @@ unnest_longer.data.frame <- 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(), - ... + transform = list() ) { ellipsis::check_dots_used() UseMethod("unnest_wider") @@ -277,12 +277,12 @@ unnest_wider <- function(data, col, #' @export unnest_wider.data.frame <- function(data, col, + ..., names_sep = NULL, simplify = TRUE, names_repair = "check_unique", ptype = list(), - transform = 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 d2a46ce01..f34e112bd 100644 --- a/R/uncount.R +++ b/R/uncount.R @@ -22,13 +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, ...) { +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 From 995fe3957863be9e28670bea2607f022dcc45a3e Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Wed, 3 Mar 2021 13:08:55 +0000 Subject: [PATCH 13/13] document() --- man/chop.Rd | 2 +- man/hoist.Rd | 8 ++++---- man/pack.Rd | 2 +- man/pivot_longer_spec.Rd | 4 ++-- man/pivot_wider_spec.Rd | 12 ++++++------ man/uncount.Rd | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/man/chop.Rd b/man/chop.Rd index 8f78ad1e4..798dc53e5 100644 --- a/man/chop.Rd +++ b/man/chop.Rd @@ -7,7 +7,7 @@ \usage{ 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.} diff --git a/man/hoist.Rd b/man/hoist.Rd index 1d02d9593..013fa5e74 100644 --- a/man/hoist.Rd +++ b/man/hoist.Rd @@ -20,25 +20,25 @@ hoist( unnest_longer( data, col, + ..., values_to = NULL, indices_to = NULL, indices_include = NULL, names_repair = "check_unique", simplify = TRUE, ptype = list(), - transform = list(), - ... + transform = list() ) unnest_wider( data, col, + ..., names_sep = NULL, simplify = TRUE, names_repair = "check_unique", ptype = list(), - transform = list(), - ... + transform = list() ) unnest_auto(data, col) diff --git a/man/pack.Rd b/man/pack.Rd index 00e595422..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 15f988518..84647374f 100644 --- a/man/pivot_longer_spec.Rd +++ b/man/pivot_longer_spec.Rd @@ -18,14 +18,14 @@ pivot_longer_spec( build_longer_spec( data, cols, + ..., names_to = "name", values_to = "value", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, - names_transform = NULL, - ... + names_transform = NULL ) } \arguments{ diff --git a/man/pivot_wider_spec.Rd b/man/pivot_wider_spec.Rd index afc6ca1d2..991a35d67 100644 --- a/man/pivot_wider_spec.Rd +++ b/man/pivot_wider_spec.Rd @@ -8,22 +8,22 @@ pivot_wider_spec( data, spec, + ..., names_repair = "check_unique", id_cols = NULL, values_fill = NULL, - values_fn = NULL, - ... + values_fn = NULL ) build_wider_spec( data, names_from = name, values_from = value, + ..., names_prefix = "", names_sep = "_", names_glue = NULL, - names_sort = FALSE, - ... + names_sort = FALSE ) } \arguments{ @@ -40,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 @@ -65,8 +67,6 @@ in the output. You will typically use this when the combination of This can be a named list if you want to apply different aggregations to different value columns.} -\item{...}{Additional arguments passed on to methods.} - \item{names_from}{<\code{\link[=tidyr_tidy_select]{tidy-select}}> A pair of arguments describing which column (or columns) to get the name of the output column (\code{names_from}), and which column (or columns) to get the diff --git a/man/uncount.Rd b/man/uncount.Rd index 1befe69c8..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,13 +12,13 @@ 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.} \item{.id}{Supply a string to create a new variable which gives a unique identifier for each created row.} - -\item{...}{Additional arguments passed on to methods.} } \description{ Performs the opposite operation to \code{\link[dplyr:count]{dplyr::count()}}, duplicating rows