Skip to content

Commit

Permalink
Implement tidyr_chop2()
Browse files Browse the repository at this point in the history
Since we don't have `vec_chop2()` yet r-lib/vctrs#1226
  • Loading branch information
DavisVaughan committed Nov 4, 2021
1 parent e7aac41 commit d6bfc3b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ tidyr_new_list <- function(x) {
x
}

# What `vec_chop2()` would be.
# Equivalent to `vec_chop(x)`, but moves names of `x` to the result.
tidyr_chop2 <- function(x) {
names <- vec_names(x)

if (!is.null(names)) {
x <- vec_set_names(x, NULL)
}

out <- vec_chop(x)

if (!is.null(names)) {
out <- vec_set_names(out, names)
}

out
}

apply_names_sep <- function(outer, inner, names_sep) {
as.character(glue("{outer}{names_sep}{inner}"))
}
Expand Down

0 comments on commit d6bfc3b

Please sign in to comment.