Skip to content

Commit 6323413

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

3 files changed

Lines changed: 6 additions & 3 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ 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("NAs were found in 'x'. They will be ignored where possible, but some plots or summaries may be affected.")
3333
}
3434

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

tests/testthat/test-helpers-mcmc.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,11 @@ 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", {
243+
test_that("prepare_mcmc_array warns but does not error if NAs", {
244244
arr[1,1,1] <- NA
245-
expect_error(prepare_mcmc_array(arr), "NAs not allowed")
245+
expect_warning(out <- prepare_mcmc_array(arr), "NAs were found")
246+
expect_s3_class(out, "mcmc_array")
247+
expect_true(anyNA(out))
246248
})
247249
test_that("prepare_mcmc_array processes non-array input types correctly", {
248250
# errors are mostly covered by tests of the many internal functions above

0 commit comments

Comments
 (0)