Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ungrouped summarise() uses summary variables correctly #2453

Merged
merged 3 commits into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions inst/include/dplyr/Result/LazySubsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace dplyr {
}

virtual bool is_summary(SEXP symbol) const {
return false;
return summary_map.has(symbol);
}

virtual int count(SEXP symbol) const {
Expand All @@ -59,6 +59,7 @@ namespace dplyr {
} else {
data[index.pos] = x;
}
summary_map.insert(symbol);
}

virtual int size() const {
Expand All @@ -77,7 +78,7 @@ namespace dplyr {
}

private:
SymbolMap symbol_map;
SymbolMap symbol_map, summary_map;
std::vector<SEXP> data;
int nr;
};
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-summarise.r
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,11 @@ test_that("min, max preserves ordered factor data (#2200)", {
expect_equal(levels(ret$min_ord), levels(test_df$ord))
expect_equal(levels(ret$max_ord), levels(test_df$ord))
})

test_that("ungrouped summarise() uses summary variables correctly (#2404)", {
df <- tibble::as_tibble(seq(1:10))
expect_equal(
df %>% summarise(value = mean(value), sd = sd(value)),
data_frame(value = 5.5, sd = NA_real_)
)
})