Skip to content

Commit

Permalink
Add name_spec arguments and use backward compatible default
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Aug 10, 2020
1 parent 99c92e7 commit 6b35f74
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BugReports: https://github.com/tidyverse/purrr/issues
Depends:
R (>= 3.2)
Imports:
ellipsis (>= 0.3.1),
lifecycle (>= 0.2.0),
magrittr (>= 1.5.0),
rlang (>= 0.4.7),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
With vctrs coercions, this is now deprecated and will become an
error in the future.

* The atomic vector variants of `flatten()` gain a `name_spec`
argument to control how the outer list names are merged with the
inner vector names.


## Features and fixes

Expand Down
22 changes: 14 additions & 8 deletions R/flatten.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' `flatten_dfr()` and `flatten_dfc()` return data frames created by
#' row-binding and column-binding respectively. They require dplyr to
#' be installed.
#' @inheritParams ellipsis::dots_empty
#' @inheritParams map
#'
#'
Expand Down Expand Up @@ -83,29 +84,34 @@ flatten <- function(.x) {
}

#' @export
#' @inheritParams vctrs::vec_unchop
#' @rdname flatten
flatten_lgl <- function(.x) {
flatten_lgl <- function(.x, ..., name_spec = "{inner}") {
ellipsis::check_dots_empty()
.x <- validate_flatten_vec(.x)
vec_unchop(.x, ptype = logical())
vec_unchop(.x, ptype = logical(), name_spec = name_spec)
}

#' @export
#' @rdname flatten
flatten_int <- function(.x) {
flatten_int <- function(.x, ..., name_spec = "{inner}") {
ellipsis::check_dots_empty()
.x <- validate_flatten_vec(.x)
vec_unchop(.x, ptype = integer())
vec_unchop(.x, ptype = integer(), name_spec = name_spec)
}

#' @export
#' @rdname flatten
flatten_dbl <- function(.x) {
flatten_dbl <- function(.x, ..., name_spec = "{inner}") {
ellipsis::check_dots_empty()
.x <- validate_flatten_vec(.x)
vec_unchop(.x, ptype = double())
vec_unchop(.x, ptype = double(), name_spec = name_spec)
}

#' @export
#' @rdname flatten
flatten_chr <- function(.x) {
flatten_chr <- function(.x, ..., name_spec = "{inner}") {
ellipsis::check_dots_empty()
.x <- validate_flatten_vec(.x)

deprecate <- FALSE
Expand All @@ -123,7 +129,7 @@ flatten_chr <- function(.x) {
signal_soft_deprecated("Numeric to character coercion is deprecated as of purrr 0.4.0.")
}

vec_unchop(out, ptype = character())
vec_unchop(out, ptype = character(), name_spec = name_spec)
}

is_chr_coercible <- function(x) {
Expand Down
28 changes: 24 additions & 4 deletions man/flatten.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b35f74

Please sign in to comment.