Skip to content

Commit

Permalink
Hybrid version of sum(na.rm = FALSE) exits early when there are mis…
Browse files Browse the repository at this point in the history
…sing values. closes #3288.
  • Loading branch information
romainfrancois committed May 29, 2018
1 parent fde94cc commit 565bd6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Expand Up @@ -17,7 +17,8 @@
- new method `group_data()` (#3489).
- joins no longer make lazy grouped data (#3566).
- new `nest_join()` function. `nest_join()` creates a list column of the matching rows. `nest_join()` + `tidyr::unnest()` is equivalent to `inner_join` (#3570).
- `last_col()` is re-exported from tidyselect (#3584)
- `last_col()` is re-exported from tidyselect (#3584).
- hybrid version of `sum(na.rm = FALSE)` exits early when there are missing values (#3288).

# dplyr 0.7.5.9001

Expand Down
8 changes: 4 additions & 4 deletions inst/include/dplyr/Result/Sum.h
Expand Up @@ -46,14 +46,14 @@ struct Sum<REALSXP, NA_RM, Index> {
for (int i = 0; i < n; i++) {
double value = ptr[indices[i]];

// !NA_RM: we don't test for NA here because += NA will give NA
// this is faster in the most common case where there are no NA
// if there are NA, we could return quicker as in the version for
// INTSXP, but we would penalize the most common case
if (NA_RM && Rcpp::traits::is_na<REALSXP>(value)) {
continue;
}

if (!NA_RM && Rcpp::traits::is_na<REALSXP>(value)) {
return NA_REAL;
}

res += value;
}

Expand Down

0 comments on commit 565bd6e

Please sign in to comment.