Skip to content

Commit

Permalink
Fix error message when data frame contains duplicated names (tidyvers…
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jul 13, 2020
1 parent c6a7ecd commit 52e885c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Imports:
magrittr (>= 1.5),
methods,
R6,
rlang (>= 0.4.6),
rlang (>= 0.4.7),
tibble (>= 2.1.3),
tidyselect (>= 1.1.0),
utils,
Expand Down
4 changes: 4 additions & 0 deletions R/data-mask.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ DataMask <- R6Class("DataMask",
private$used <- rep(FALSE, ncol(data))

names_bindings <- chr_unserialise_unicode(names2(data))
if (anyDuplicated(names_bindings)) {
abort("Can't transform a data frame with duplicate names.")
}

private$resolved <- set_names(vector(mode = "list", length = ncol(data)), names_bindings)

promise_fn <- function(index, chunks = resolve_chunks(index), name = names_bindings[index]) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-arrange-errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ duplicated column name

> tibble(x = 1, x = 1, .name_repair = "minimal") %>% arrange(x)
Error: arrange() failed at implicit mutate() step.
x Can't bind data because some arguments have the same name
x Can't transform a data frame with duplicate names.


error in mutate() step
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-summarise-errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,10 @@ x Column `b` not found in `.data`
i Input `c` is `.data$b`.
i The error occurred in group 1: a = 1.


Duplicate column names
======================

> tibble(x = 1, x = 1, .name_repair = "minimal") %>% summarise(x)
Error: Can't transform a data frame with duplicate names.

3 changes: 3 additions & 0 deletions tests/testthat/test-summarise.r
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,8 @@ test_that("summarise() gives meaningful errors", {
"# .data pronoun"
summarise(tibble(a = 1), c = .data$b)
summarise(group_by(tibble(a = 1:3), a), c = .data$b)

"# Duplicate column names"
tibble(x = 1, x = 1, .name_repair = "minimal") %>% summarise(x)
})
})

0 comments on commit 52e885c

Please sign in to comment.