Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ nest <- function(.data, ..., .names_sep = NULL, .key = deprecated()) {

.key <- if (missing(.key)) "data" else as.character(ensym(.key))

cols_fixed_expr <- expr(c(!!!cols_bad))
if (length(cols_bad) == 1L) {
cols_bad <- cols_bad[[1]]
cols_fixed_expr <- expr(!!cols_bad)
} else {
cols_fixed_expr <- expr(c(!!!cols_bad))
}

cols_fixed_label <- as_label(cols_fixed_expr)
cols_fixed <- quos(!!.key := !!cols_fixed_expr)

Expand Down
12 changes: 10 additions & 2 deletions tests/testthat/_snaps/nest.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@
out <- nest(df, y)
Warning <warning>
All elements of `...` must be named.
Did you want `data = c(y)`?
Did you want `data = y`?

---

Code
out <- nest(df, -y)
Warning <warning>
All elements of `...` must be named.
Did you want `data = -y`?

# only warn about unnamed inputs (#1175)

Expand All @@ -68,7 +76,7 @@
out <- nest(df, y, .key = "y")
Warning <warning>
All elements of `...` must be named.
Did you want `y = c(y)`?
Did you want `y = y`?

# can control output column name when nested

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ test_that("unnest keeps list cols", {

test_that("warn about old style interface", {
df <- tibble(x = c(1, 1, 1), y = 1:3)

expect_snapshot(out <- nest(df, y))
expect_named(out, c("x", "data"))

expect_snapshot(out <- nest(df, -y))
expect_named(out, c("y", "data"))
})

test_that("only warn about unnamed inputs (#1175)", {
Expand Down