Skip to content

Commit

Permalink
Check that data_frames have unique names.
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 29, 2015
1 parent 77dba6b commit 3187f86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ check_data_frame <- function(x) {
invalid_df("Each variable must be named", x, which(bad_name))
}

dups <- duplicated(names_x)
if (any(dups)) {
invalid_df("Each variable must have a unique name", x, dups)
}

# Types
is_1d <- vapply(x, is_1d, logical(1))
if (any(!is_1d)) {
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-data_frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,10 @@ test_that("columns must be named (#1101)", {
"Each variable must be named"
)
})

test_that("names must be unique (#820)", {
expect_error(
check_data_frame(list(x = 1, x = 2)),
"Each variable must have a unique name"
)
})

0 comments on commit 3187f86

Please sign in to comment.