Skip to content

Commit

Permalink
better error message with a suggestion to use forcats for implicit mi…
Browse files Browse the repository at this point in the history
…ssing values in factor when used in group_by.

Eliminate the lazy use of the data frame from MASS 📦
  • Loading branch information
romainfrancois committed May 2, 2018
1 parent b5c864c commit ebcfbcb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/group_indices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ class FactorSlicer : public Slicer {
int idx = range[i];
int value = f[idx];

// will support it later
if (value == NA_INTEGER) stop("NA not supported");
if (value == NA_INTEGER) {
bad_col(visitors.name(depth), "contains implicit missing values. Consider `forcats::fct_explicit_na` to turn them explicit");
}
indices[value - 1].push_back(idx);
}
}


int depth;

const std::vector<SEXP>& data;
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-group-by.r
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ test_that("group_by uses shallow copy", {
})

test_that("FactorVisitor handles NA. #183", {
skip("until we can group again by a factor that has NA")
g <- group_by(MASS::survey, M.I)
expect_equal(g$M.I, MASS::survey$M.I)
d <- data.frame(x = 1:3, f = factor(c("a", "b", NA)))
expect_error(group_by(d, f), "Column `f` contains implicit missing values")
})

test_that("group_by orders by groups. #242", {
Expand Down

0 comments on commit ebcfbcb

Please sign in to comment.