Skip to content

Commit

Permalink
better error message with NA columns. closes #1101
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Jul 16, 2015
1 parent 683445a commit 75e8303
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

* Fixed `bind_rows` `POSIXct` bug (#1125).

* `as_data_frame` gives better error message with NA column names (#1101).

# dplyr 0.4.2

This is a minor release containing fixes for a number of crashes and issues identified by R CMD CHECK. There is one new "feature": dplyr no longer complains about unrecognised attributes, and instead just copies them over to the output.
Expand Down
3 changes: 2 additions & 1 deletion R/dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ as_data_frame <- function(x) {
return(x)
}

if (any(names2(x) == "")) {
names_x <- names2(x)
if (any(is.na(names_x) | names_x == "")){
stop("All elements must be named", call. = FALSE)
}

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-data_frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ test_that("Zero column list makes 0 x 0 tbl_df", {
expect_is(zero, "tbl_df")
expect_equal(dim(zero), c(0L, 0L))
})

test_that("error on NA column names (#1101)", {
df <- data.frame( x = 1:10, y = 1:10 )
names(df)[1] <- NA
expect_error( as_data_frame(df), "All elements must be named" )
})

0 comments on commit 75e8303

Please sign in to comment.