Skip to content

Commit

Permalink
Fixed a bug with transmute_weights()
Browse files Browse the repository at this point in the history
  • Loading branch information
marberts committed Aug 13, 2024
1 parent 94c2224 commit 34ebd45
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- `splice_index()` now keeps names.

- Fixed a bug with `transmute_weights()` where the weights could be negative.

## Version 0.6.1

- Updated maintainer email.
Expand Down
2 changes: 1 addition & 1 deletion R/weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rdiff <- function(a, b, r) {
} else if (r == 1) {
a - b
} else {
a^r - b^r
(a^r - b^r) / r
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ test_that("weights transmute correctly", {
expect_equal(transmute_weights(2, 1)(c(1, NA)), c(1, NA))
expect_equal(transmute_weights(-1, 1)(x, w), scale_weights(w / x))
expect_equal(transmute_weights(1, -1)(xna, w), scale_weights(w * xna))
# Used to give negative weights.
expect_equal(transmute_weights(-1, 1)(1:3 / 2, 1:3 / 6), rep(1 / 3, 3))
expect_equal(
transmute_weights(7, -3)(x, transmute_weights(-3, 7)(x, w)),
scale_weights(w)
Expand Down

0 comments on commit 34ebd45

Please sign in to comment.