forked from deephaven/deephaven-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
agg_all_by()
to the R client and add error handling around empt…
…y aggregations in `agg_by()` (deephaven#4465) * Support agg_all_by at the R level, provide a stable API that allows the underlying C++ to change freely * Snake case * A little more snake case * Helpful errors in agg_by * Code review suggestions
- Loading branch information
1 parent
2bf5958
commit fa7ca6d
Showing
5 changed files
with
272 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,85 @@ | ||
#' @export | ||
Aggregation <- R6Class("Aggregation", | ||
cloneable = FALSE, | ||
public = list( | ||
.internal_rcpp_object = NULL, | ||
initialize = function(aggregation) { | ||
if (class(aggregation) != "Rcpp_INTERNAL_Aggregate") { | ||
stop("'aggregation' should be an internal Deephaven Aggregation. If you're seeing this,\n you are trying to call the constructor of an Aggregation directly, which is not advised.\n Please use one of the provided aggregation functions instead.") | ||
.internal_num_cols = NULL, | ||
.internal_agg_name = NULL, | ||
initialize = function(aggregation, agg_name, ...) { | ||
self$.internal_agg_name <- agg_name | ||
args <- list(...) | ||
if (any(names(args) == "cols")) { | ||
self$.internal_num_cols <- length(args$cols) | ||
} | ||
self$.internal_rcpp_object <- aggregation | ||
self$.internal_rcpp_object <- do.call(aggregation, args) | ||
} | ||
) | ||
) | ||
|
||
### All of the functions below return an instance of the above class | ||
|
||
#' @export | ||
agg_first <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_first(cols))) | ||
return(Aggregation$new(INTERNAL_agg_first, "agg_first", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_last <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_last(cols))) | ||
return(Aggregation$new(INTERNAL_agg_last, "agg_last", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_min <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_min(cols))) | ||
return(Aggregation$new(INTERNAL_agg_min, "agg_min", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_max <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_max(cols))) | ||
return(Aggregation$new(INTERNAL_agg_max, "agg_max", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_sum <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_sum(cols))) | ||
return(Aggregation$new(INTERNAL_agg_sum, "agg_sum", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_abs_sum <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_abs_sum(cols))) | ||
return(Aggregation$new(INTERNAL_agg_abs_sum, "agg_abs_sum", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_avg <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_avg(cols))) | ||
return(Aggregation$new(INTERNAL_agg_avg, "agg_avg", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_w_avg <- function(wcol, cols = character()) { | ||
verify_string("wcol", wcol, TRUE) | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_w_avg(wcol, cols))) | ||
return(Aggregation$new(INTERNAL_agg_w_avg, "agg_w_avg", wcol=wcol, cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_median <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_median(cols))) | ||
return(Aggregation$new(INTERNAL_agg_median, "agg_median", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_var <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_var(cols))) | ||
return(Aggregation$new(INTERNAL_agg_var, "agg_var", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_std <- function(cols = character()) { | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_std(cols))) | ||
return(Aggregation$new(INTERNAL_agg_std, "agg_std", cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_percentile <- function(percentile, cols = character()) { | ||
verify_in_unit_interval("percentile", percentile, TRUE) | ||
verify_string("cols", cols, FALSE) | ||
return(Aggregation$new(INTERNAL_agg_percentile(percentile, cols))) | ||
return(Aggregation$new(INTERNAL_agg_percentile, "agg_percentile", percentile=percentile, cols=cols)) | ||
} | ||
|
||
#' @export | ||
agg_count <- function(col) { | ||
verify_string("col", col, TRUE) | ||
return(Aggregation$new(INTERNAL_agg_count(col))) | ||
} | ||
return(Aggregation$new(INTERNAL_agg_count, "agg_count", col=col)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.