Skip to content

Commit 1f57c48

Browse files
committed
Merge branch 'master' of github.com:hadley/dplyr
2 parents 1c0e907 + 4801e3b commit 1f57c48

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@
158158
missing values (#774). `row_number()` doesn't segfault when giving an external
159159
variable with the wrong number of variables (#781)
160160

161+
* `group_indices` handles the edge case when there are no variables (#867)
162+
161163
# dplyr 0.3.0.1
162164

163165
* Fixed problem with test script on Windows.

R/funs.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Create a list of functions calls.
22
#'
3-
#' \code{funs} provides a flexible to generate a named list of functions for
4-
#' input to other functions like \code{colwise}.
3+
#' \code{funs} provides a flexible way to generate a named list of functions for
4+
#' input to other functions like \code{summarise_each}.
55
#'
66
#' @param dots,... A list of functions specified by:
77
#'

src/group_indices.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ IntegerVector grouped_indices_grouped_df_impl( GroupedDataFrame gdf ){
2222
// [[Rcpp::export]]
2323
IntegerVector grouped_indices_impl( DataFrame data, ListOf<Symbol> symbols ){
2424
int nsymbols = symbols.size() ;
25+
if( nsymbols == 0 )
26+
return rep(1, data.nrows()) ;
2527
CharacterVector vars(nsymbols) ;
2628
for( int i=0; i<nsymbols; i++){
2729
vars[i] = PRINTNAME(symbols[i]) ;

tests/testthat/test-group-indices.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ test_that("group_indices from ungrouped or grouped gives same result", {
66
expect_equal(res1, res2)
77
})
88

9+
test_that("group_indices handles the case where no variable is given (#867)", {
10+
res <- group_indices(mtcars)
11+
expect_true( all(res==1L) )
12+
})
13+
14+
test_that("group_indices handles grouped data and no arguments", {
15+
res1 <- mtcars %>% group_by(cyl) %>% group_indices()
16+
res2 <- mtcars %>% group_indices(cyl)
17+
expect_equal(res1, res2)
18+
})
19+

0 commit comments

Comments
 (0)