Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# bayesplot (development version)

* Fixed `validate_chain_list()` colnames check to compare all chains, not just the first two.
* Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`.
* Fixed `is_chain_list()` to correctly reject empty lists instead of silently returning `TRUE`.
* Added unit tests for `mcmc_areas_ridges_data()`, `mcmc_parcoord_data()`, and `mcmc_trace_data()`.
Expand Down
8 changes: 2 additions & 6 deletions R/helpers-mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,8 @@ validate_chain_list <- function(x) {
abort("Each chain should have the same number of iterations.")
}

cnames <- sapply(x, colnames)
if (is.array(cnames)) {
same_params <- identical(cnames[, 1], cnames[, 2])
} else {
same_params <- length(unique(cnames)) == 1
}
cnames <- lapply(x, colnames)
same_params <- all(vapply(cnames[-1], identical, logical(1), cnames[[1]]))
if (!same_params) {
abort(paste(
"The parameters for each chain should be in the same order",
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-helpers-mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ test_that("validate_chain_list works", {
"Each chain should have the same number of iterations")
})

test_that("validate_chain_list detects colnames mismatch in chain 3+", {
ch <- matrix(rnorm(20), nrow = 2, dimnames = list(NULL, c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j")))
chain3_bad <- ch
colnames(chain3_bad)[1] <- "z"
chains_ok <- list(ch, ch, ch)
chains_bad <- list(ch, ch, chain3_bad)

expect_identical(validate_chain_list(chains_ok), chains_ok)
expect_error(validate_chain_list(chains_bad), "parameters for each chain")
})

test_that("chain_list2array works", {
expect_mcmc_array(chain_list2array(chainlist))
expect_mcmc_array(chain_list2array(chainlist1))
Expand Down
Loading