From 7ee3c0e6a5599c5544065c836aa193e166fc6f68 Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Tue, 7 Apr 2026 14:21:46 +0530 Subject: [PATCH 1/3] fix validate_chain_list() colnames check to compare all chains --- R/helpers-mcmc.R | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/R/helpers-mcmc.R b/R/helpers-mcmc.R index 0f3970d9..179ec020 100644 --- a/R/helpers-mcmc.R +++ b/R/helpers-mcmc.R @@ -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", From 76fe77bbf2b9fe2f96fbdddf4ea895dd3cae7c11 Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Tue, 7 Apr 2026 14:28:12 +0530 Subject: [PATCH 2/3] update news.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c8f7d131..a58443f8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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()`. From 76c8db6cb94bdeb3730b63602bbf03a743d09cb0 Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Tue, 7 Apr 2026 14:31:23 +0530 Subject: [PATCH 3/3] add regression test --- tests/testthat/test-helpers-mcmc.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-helpers-mcmc.R b/tests/testthat/test-helpers-mcmc.R index 409b0b99..84347f23 100644 --- a/tests/testthat/test-helpers-mcmc.R +++ b/tests/testthat/test-helpers-mcmc.R @@ -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))