Skip to content

Commit

Permalink
Merge pull request #84 from mrc-ide/mrc-5882
Browse files Browse the repository at this point in the history
Fix pack bug
  • Loading branch information
richfitz authored Oct 15, 2024
2 parents b5d485f + b40ff36 commit ab2368f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: monty
Title: Monte Carlo Models
Version: 0.2.17
Version: 0.2.18
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
5 changes: 3 additions & 2 deletions R/packer.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,10 @@ monty_packer <- function(scalar = NULL, array = NULL, fixed = NULL,
for (nm in names(shape)) {
ret[idx[[nm]], ] <- p[[nm]]
}

drop <- length(shp) == 0 ||
(length(shp) == 1 && (length(shape) == 0 || all(lengths(shape) == 0)))
(length(shp) == 1 &&
(length(shape) == 0 || all(lengths(shape) == 0)) &&
length(ret) == length(idx))
if (drop) {
dim(ret) <- NULL
} else if (length(shp) > 1) {
Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test-packer.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_that("trivial packer", {
"Incorrect length input; expected 1 but given 2")
expect_equal(xp$pack(list(a = 1)), 1)
expect_equal(xp$pack(list(a = 1:2)),
1:2)
rbind(1:2))

expect_equal(xp$index(), list(a = 1))
})
Expand Down Expand Up @@ -445,3 +445,10 @@ test_that("don't allow things other than character vectors for now", {
p$subset(1),
"Invalid input for 'keep'; this must currently be a character vector")
})


test_that("can add matrix dimensions when unpacking", {
p <- monty_packer(c("a", "b", "c"))
m <- matrix(1:12, 3, 4)
expect_equal(p$pack(p$unpack(m)), m)
})

0 comments on commit ab2368f

Please sign in to comment.