diff --git a/NEWS.md b/NEWS.md index e7fc9138..af643760 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # bayesplot (development version) +* 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()`. * Added unit tests for `ppc_error_data()` and `ppc_loo_pit_data()` covering output structure, argument handling, and edge cases. * Added vignette sections demonstrating `*_data()` companion functions for building custom ggplot2 visualizations (#435) diff --git a/R/helpers-mcmc.R b/R/helpers-mcmc.R index 8d794d1a..0f3970d9 100644 --- a/R/helpers-mcmc.R +++ b/R/helpers-mcmc.R @@ -247,6 +247,9 @@ df_with_chain2array <- function(x) { #' @param x object to check #' @return TRUE or FALSE is_chain_list <- function(x) { + if (length(x) == 0) { + return(FALSE) + } check1 <- !is.data.frame(x) && is.list(x) dims <- try(sapply(x, function(chain) length(dim(chain))), silent=TRUE) if (inherits(dims, "try-error")) { diff --git a/tests/testthat/test-helpers-mcmc.R b/tests/testthat/test-helpers-mcmc.R index a116be73..409b0b99 100644 --- a/tests/testthat/test-helpers-mcmc.R +++ b/tests/testthat/test-helpers-mcmc.R @@ -156,6 +156,7 @@ test_that("is_chain_list works", { expect_true(is_chain_list(chainlist)) expect_true(is_chain_list(chainlist1)) expect_true(is_chain_list(chainlist1chain)) + expect_false(is_chain_list(list())) }) test_that("validate_chain_list works", {