Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions r/R/dplyr-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,27 @@ agg_funcs$all <- function(x, na.rm = FALSE) {
options = list(na.rm = na.rm, na.min_count = 0L)
)
}

agg_funcs$mean <- function(x, na.rm = FALSE) {
list(
fun = "mean",
data = x,
options = list(na.rm = na.rm, na.min_count = 0L)
)
}
# na.rm not currently passed in due to ARROW-13691
agg_funcs$sd <- function(x, na.rm = FALSE, ddof = 1) {
list(
fun = "stddev",
data = x,
options = list(ddof = ddof)
)
}
# na.rm not currently passed in due to ARROW-13691
agg_funcs$var <- function(x, na.rm = FALSE, ddof = 1) {
list(
fun = "variance",
data = x,
options = list(ddof = ddof)
)
}
3 changes: 2 additions & 1 deletion r/src/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ std::shared_ptr<arrow::compute::FunctionOptions> make_compute_options(
step);
}

if (func_name == "variance" || func_name == "stddev") {
if (func_name == "variance" || func_name == "stddev" || func_name == "hash_variance" ||
func_name == "hash_stddev") {
using Options = arrow::compute::VarianceOptions;
return std::make_shared<Options>(cpp11::as_cpp<int64_t>(options["ddof"]));
}
Expand Down
63 changes: 63 additions & 0 deletions r/tests/testthat/test-dplyr-aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,73 @@ test_that("Group by sum on dataset", {
summarize(total = sum(int)) %>%
arrange(some_grouping) %>%
collect(),
tbl,
)
})

test_that("Group by mean on dataset", {
expect_dplyr_equal(
input %>%
group_by(some_grouping) %>%
summarize(mean = mean(int, na.rm = TRUE)) %>%
arrange(some_grouping) %>%
collect(),
tbl
)

expect_dplyr_equal(
input %>%
group_by(some_grouping) %>%
summarize(mean = mean(int, na.rm = FALSE)) %>%
arrange(some_grouping) %>%
collect(),
tbl
)
})

test_that("Group by sd on dataset", {
expect_dplyr_equal(
input %>%
group_by(some_grouping) %>%
summarize(sd = sd(int, na.rm = TRUE)) %>%
arrange(some_grouping) %>%
collect(),
tbl
)

skip("ARROW-13691 - na.rm not yet implemented for VarianceOptions")
expect_dplyr_equal(
input %>%
group_by(some_grouping) %>%
summarize(sd = sd(int, na.rm = FALSE)) %>%
arrange(some_grouping) %>%
collect(),
tbl
)
})

test_that("Group by var on dataset", {
expect_dplyr_equal(
input %>%
group_by(some_grouping) %>%
summarize(var = var(int, na.rm = TRUE)) %>%
arrange(some_grouping) %>%
collect(),
tbl
)

skip("ARROW-13691 - na.rm not yet implemented for VarianceOptions")
expect_dplyr_equal(
input %>%
group_by(some_grouping) %>%
summarize(var = var(int, na.rm = FALSE)) %>%
arrange(some_grouping) %>%
collect(),
tbl
)
})


test_that("Group by any/all", {
withr::local_options(list(arrow.debug = TRUE))

Expand Down