Skip to content

Commit

Permalink
loo_compare: fix error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Dec 11, 2023
1 parent 82d737a commit e5fd723
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/loo.R
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,16 @@ loo_compare.brmsfit <- function(x, ..., criterion = c("loo", "waic", "kfold"),
loos <- named_list(names(models))
for (i in seq_along(models)) {
models[[i]] <- restructure(models[[i]])
loos[[i]] <- get_criterion(models[[i]], criterion)
if (is.null(loos[[i]])) {
loo_i <- get_criterion(models[[i]], criterion)
if (is.null(loo_i)) {
stop2(
"Model '", names(models)[i], "' does not contain a precomputed '",
criterion, "' criterion. See ?loo_compare.brmsfit for help."
)
}
# only assign object to list after checking if non-null
# otherwise the index may be out of bounds in the error check
loos[[i]] <- loo_i
}
loo_compare(loos)
}
Expand Down

0 comments on commit e5fd723

Please sign in to comment.