Skip to content

Commit 1f3d4ce

Browse files
committed
allow NAs in prepare_mcmc_array
1 parent 44c3e5c commit 1f3d4ce

3 files changed

Lines changed: 10 additions & 4 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+
* `prepare_mcmc_array()` now warns instead of erroring on `NA`s in the input.
34
* `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated.
45
* Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`.
56
* Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`.

R/helpers-mcmc.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ prepare_mcmc_array <- function(x,
2929
abort("Arrays should have 2 or 3 dimensions. See help('MCMC-overview').")
3030
}
3131
if (anyNA(x)) {
32-
abort("NAs not allowed in 'x'.")
32+
warn(
33+
"NAs were found in 'x'. `prepare_mcmc_array()` does not remove them; some plots may render with missing values dropped, while summary functions (e.g. intervals, densities, diagnostics) may produce misleading results or error. Consider removing NAs before plotting or summarizing."
34+
)
3335
}
3436

3537
if (rlang::is_quosures(pars)) {

tests/testthat/test-helpers-mcmc.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,12 @@ test_that("transformations recycled properly if not a named list", {
240240

241241

242242
# prepare_mcmc_array ------------------------------------------------------
243-
test_that("prepare_mcmc_array errors if NAs", {
244-
arr[1,1,1] <- NA
245-
expect_error(prepare_mcmc_array(arr), "NAs not allowed")
243+
test_that("prepare_mcmc_array warns but does not error if NAs", {
244+
arr_na <- arr
245+
arr_na[1,1,1] <- NA
246+
expect_warning(out <- prepare_mcmc_array(arr_na), "NAs were found")
247+
expect_s3_class(out, "mcmc_array")
248+
expect_true(anyNA(out))
246249
})
247250
test_that("prepare_mcmc_array processes non-array input types correctly", {
248251
# errors are mostly covered by tests of the many internal functions above

0 commit comments

Comments
 (0)