Skip to content

Commit

Permalink
fix distinct for zero columns data frames. closes tidyverse#1437
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Oct 6, 2015
1 parent db17685 commit bf6477c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

* Faster joining by character column (#1386).

* Fixed `distinct` for zero column data frames (#1437).

# dplyr 0.4.3

## Improved encoding support
Expand Down
2 changes: 2 additions & 0 deletions src/distinct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using namespace dplyr ;

// [[Rcpp::export]]
SEXP distinct_impl( DataFrame df, CharacterVector vars){
if( df.size() == 0 )
return df ;
check_valid_colnames(df) ;
if( !vars.size() ){
vars = df.names() ;
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ test_that("grouped_by uses grouping vars & preserves groups", {
compare_tbls(tbls[c("df", "dt")],
function(x) x %>% group_by(x) %>% distinct(y))
})

test_that("distinct works for 0-sized columns (#1437)", {
df <- data_frame(x=1:10) %>% select(-x)
ddf <- distinct(df)
expect_equal( ncol(ddf), 0L )
})

0 comments on commit bf6477c

Please sign in to comment.