Skip to content

Commit

Permalink
Merge pull request #259 from stan-dev/bind_draws_list
Browse files Browse the repository at this point in the history
allow lists to be passed to bind_draws
  • Loading branch information
paul-buerkner authored Oct 18, 2022
2 parents c95d6de + a655ef4 commit f343850
Show file tree
Hide file tree
Showing 5 changed files with 32 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: posterior
Title: Tools for Working with Posterior Distributions
Version: 1.3.1
Version: 1.3.1.9000
Date: 2022-09-06
Authors@R: c(person("Paul-Christian", "Bürkner", email = "[email protected]", role = c("aut", "cre")),
person("Jonah", "Gabry", email = "[email protected]", role = c("aut")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ S3method(bind_draws,draws_df)
S3method(bind_draws,draws_list)
S3method(bind_draws,draws_matrix)
S3method(bind_draws,draws_rvars)
S3method(bind_draws,list)
S3method(c,rvar)
S3method(cbind,rvar)
S3method(cdf,rvar)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# posterior 1.3.1.9000

### Enhancements

* Allow lists of draws objects to be passed as the first argument to
`bind_draws()` (#253).


# posterior 1.3.1

* Minor release that fixes some CRAN check failures.


# posterior 1.3.0

### Enhancements
Expand Down
7 changes: 6 additions & 1 deletion R/bind_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ bind_draws.NULL <- function(x, ..., along = "variable") {
if (!length(dots)) {
stop_no_call("All objects passed to 'bind_draws' are NULL.")
}
do.call(bind_draws, dots)
do.call("bind_draws", dots)
}

#' @export
bind_draws.list <- function(x, ..., along = "variable") {
do.call("bind_draws", c(x, ..., along = along))
}

# check if function output is the same across objects
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-bind_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ test_that("bind_draws works for draws_rvars objects", {
expect_equal(draws_new, draws1)
})

test_that("bind_draws works for list objects", {
draws1 <- as_draws_df(example_draws())
draws2 <- subset_draws(draws1, chain = 2)
draws3 <- subset_draws(draws1, chain = 3)

draws12 <- bind_draws(draws1, draws2, along = "chain")
draws_all <- bind_draws(draws1, draws2, draws3, along = "chain")
expect_equal(bind_draws(list(draws1, draws2), along = "chain"), draws12)
expect_equal(bind_draws(list(draws1, draws2, draws3), along = "chain"), draws_all)

draws4 <- subset_draws(draws1, chain = 4)
draws_all <- bind_draws(draws2, draws3, draws4, along = "iteration")
expect_equal(bind_draws(list(draws2, draws3, draws4), along = "iteration"), draws_all)
})

test_that("bind_draws errors if all NULL", {
expect_error(bind_draws(NULL, NULL), "All objects passed to 'bind_draws' are NULL")
})
Expand Down

0 comments on commit f343850

Please sign in to comment.