Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 3 additions & 4 deletions duckdb-rfuns-r/R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
#' @rdname aggregate
#' @export
rfuns_sum <- function(x, ...) {
rfuns("aggregate", "sum", tibble(x = x), ...)
rfuns("sum", tibble(x = x), ..., op = "aggregate")
}

#' @rdname aggregate
#' @export
rfuns_min <- function(x, ...) {
rfuns("aggregate", "min", tibble(x = x), ...)
rfuns("min", tibble(x = x), ..., op = "aggregate")
}

#' @rdname aggregate
#' @export
rfuns_max <- function(x, ...) {
rfuns("aggregate", "max", tibble(x = x), ...)
rfuns("max", tibble(x = x), ..., op = "aggregate")
}

6 changes: 3 additions & 3 deletions duckdb-rfuns-r/R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @export
rfuns_is.na <- function(x) {
rfuns("project", "is.na", tibble(x = x))
rfuns("is.na", tibble(x = x))
}

#' as.integer()
Expand All @@ -13,7 +13,7 @@ rfuns_is.na <- function(x) {
#'
#' @export
rfuns_as.integer <- function(x) {
rfuns("project", "as.integer", tibble(x = x))
rfuns("as.integer", tibble(x = x))
}

#' as.numeric()
Expand All @@ -22,5 +22,5 @@ rfuns_as.integer <- function(x) {
#'
#' @export
rfuns_as.numeric <- function(x) {
rfuns("project", "as.numeric", tibble(x = x))
rfuns("as.numeric", tibble(x = x))
}
3 changes: 2 additions & 1 deletion duckdb-rfuns-r/R/rfuns.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rfuns <- function(op = c("project", "aggregate"), fun, data, ..., error_call = caller_env()) {
rfuns <- function(fun, data, ..., error_call = caller_env(), op = c("project", "aggregate")) {
withr::local_options(list(duckdb.materialize_message = FALSE))
con <- local_duckdb_con()

Expand All @@ -13,6 +13,7 @@ rfuns <- function(op = c("project", "aggregate"), fun, data, ..., error_call = c
)
)

op <- rlang::arg_match(op, error_call = error_call)
result <- switch(op,
"project" = duckdb:::rel_project(in_rel, exprs),
"aggregate" = duckdb:::rel_aggregate(in_rel, list(), exprs)
Expand Down
8 changes: 4 additions & 4 deletions duckdb-rfuns-r/tests/testthat/test-sum.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ test_that("r_base::sum(<BOOLEAN>)", {
x <- c(TRUE, TRUE, FALSE, NA)
empty <- logical()

expect_equal(rfuns_sum(x, na.rm = TRUE) , sum(x, na.rm = TRUE))
expect_equal(rfuns_sum(x, na.rm = FALSE), sum(x, na.rm = FALSE))
expect_equal(rfuns_sum(x, na.rm = TRUE)[1] , sum(x, na.rm = TRUE))
expect_equal(rfuns_sum(x, na.rm = FALSE)[1], sum(x, na.rm = FALSE))
expect_equal(rfuns_sum(empty, na.rm = FALSE), sum(empty, na.rm = TRUE))
expect_equal(rfuns_sum(empty, na.rm = TRUE) , sum(empty, na.rm = FALSE))

expect_equal(rfuns_sum(x) , sum(x))
expect_equal(rfuns_sum(x), sum(x))
expect_equal(rfuns_sum(x)[1] , sum(x))
expect_equal(rfuns_sum(x)[1], sum(x))
expect_equal(rfuns_sum(empty), sum(empty))
expect_equal(rfuns_sum(empty), sum(empty))
})
Expand Down
2 changes: 1 addition & 1 deletion src/include/rfuns_extension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ScalarFunctionSet base_r_is_na();
ScalarFunctionSet base_r_as_integer();
ScalarFunctionSet base_r_as_numeric();

// sum
// aggregates
AggregateFunctionSet base_r_sum();
AggregateFunctionSet base_r_min();
AggregateFunctionSet base_r_max();
Expand Down