Skip to content

Commit

Permalink
Merge pull request #135 from hubverse-org/134-use-of-allequal-in-simp…
Browse files Browse the repository at this point in the history
…le_ensemble-sometimes-throws-an-error

Fix `simple_ensemble()` bug caused by `all.equal()`
  • Loading branch information
lshandross authored Sep 27, 2024
2 parents 0b048b6 + 5db0106 commit 91f882b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# hubEnsembles (development version)

* Fix bug in `simple_ensemble()` where `all.equal()` was sometimes throwing an error (#134)

# hubEnsembles 0.1.8

* Update README to point to hubverse R-universe
Expand Down
2 changes: 1 addition & 1 deletion R/simple_ensemble.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ simple_ensemble <- function(model_out_tbl, weights = NULL,
}

# don't interpolate when calling `matrixStats::weightedMedian`
if (isTRUE(all.equal(agg_fun, matrixStats::weightedMedian))) {
if (identical(agg_fun, matrixStats::weightedMedian)) {
agg_args <- c(agg_args, list(interpolate = FALSE))
}

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-simple_ensemble.R
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,17 @@ test_that("duplicate forecast values still result in correct weighted median", {

expect_equal(weighted_median_expected, weighted_median_actual)
})

test_that("simple_ensemble accepts custom functions without error", {
geometric_mean <- function(x) {
n <- length(x)
return(prod(x)^(1 / n))
}

model_outputs |>
hubEnsembles::simple_ensemble(
agg_fun = geometric_mean,
model_id = "simple-ensemble-geometric"
) |>
expect_no_error()
})

0 comments on commit 91f882b

Please sign in to comment.