Skip to content

Commit

Permalink
Fixed bug with transmute_weights()
Browse files Browse the repository at this point in the history
  • Loading branch information
marberts committed Mar 23, 2024
1 parent 8803146 commit 120528f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gpindex
Title: Generalized Price and Quantity Indexes
Version: 0.6.0.9013
Version: 0.6.0.9014
Authors@R: c(
person("Steve", "Martin", role = c("aut", "cre", "cph"),
email = "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion R/weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ transmute_weights <- function(r, s) {
function(x, w = NULL) {
if (r == s) {
if (is.null(w)) {
return(rep.int(1 / length(x), length(x)))
w <- rep.int(1, length(x))
}
if (length(x) != length(w)) {
stop("'x' and 'w' must be the same length")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ f <- factor(sample(letters[1:3], 15, TRUE))

test_that("weights transmute correctly", {
expect_equal(transmute_weights(2, 2)(x), rep(1 / 15, length(x)))
expect_equal(transmute_weights(2, 2)(c(1:3, NA)), c(1, 1, 1, NA) / 3)
expect_equal(
transmute_weights(0, 0)(xna, w),
scale_weights(replace(w, 2, NA))
Expand Down

0 comments on commit 120528f

Please sign in to comment.