Skip to content

Commit a86c556

Browse files
authored
Merge pull request #517 from utkarshpawade/refactor/sapply-to-vapply-type-safety
is_chain_list: return FALSE for empty lists
2 parents 5c1d015 + 2ad7ef4 commit a86c556

3 files changed

Lines changed: 5 additions & 0 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# bayesplot (development version)
22

3+
* Fixed `is_chain_list()` to correctly reject empty lists instead of silently returning `TRUE`.
34
* Added unit tests for `mcmc_areas_ridges_data()`, `mcmc_parcoord_data()`, and `mcmc_trace_data()`.
45
* Added unit tests for `ppc_error_data()` and `ppc_loo_pit_data()` covering output structure, argument handling, and edge cases.
56
* Added vignette sections demonstrating `*_data()` companion functions for building custom ggplot2 visualizations (#435)

R/helpers-mcmc.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ df_with_chain2array <- function(x) {
247247
#' @param x object to check
248248
#' @return TRUE or FALSE
249249
is_chain_list <- function(x) {
250+
if (length(x) == 0) {
251+
return(FALSE)
252+
}
250253
check1 <- !is.data.frame(x) && is.list(x)
251254
dims <- try(sapply(x, function(chain) length(dim(chain))), silent=TRUE)
252255
if (inherits(dims, "try-error")) {

tests/testthat/test-helpers-mcmc.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ test_that("is_chain_list works", {
156156
expect_true(is_chain_list(chainlist))
157157
expect_true(is_chain_list(chainlist1))
158158
expect_true(is_chain_list(chainlist1chain))
159+
expect_false(is_chain_list(list()))
159160
})
160161

161162
test_that("validate_chain_list works", {

0 commit comments

Comments
 (0)