Skip to content

Commit

Permalink
Add try in call for models in bm_RunModelsLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
MayaGueguen committed Jan 29, 2024
1 parent c4bf63d commit 4cf9ef2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/bm_RunModelsLoop.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ bm_RunModel <- function(model, run.name, dir.name = '.'

## RUN model ----------------------------------------------------
model.call <- paste0(bm.opt@package, "::", bm.opt@func)
model.sp <- do.call(eval(parse(text = model.call)), bm.opt.val)
model.sp <- try(do.call(eval(parse(text = model.call)), bm.opt.val))


## GET results --------------------------------------------------
Expand Down Expand Up @@ -440,7 +440,11 @@ bm_RunModel <- function(model, run.name, dir.name = '.'
temp_workdir = NULL

if (model != "MAXENT") {
if (model == "SRE" && bm.opt.val$do.extrem == FALSE) {
if (inherits(model.sp, "try-error")) {
g.pred <- NA
class(g.pred) <- "try-error"
cat("\n*** Error in ", model, ", calibration failed")
} else if (model == "SRE" && bm.opt.val$do.extrem == FALSE) {
g.pred <- model.sp
} else {
g.pred <- try(predict(model.bm, data_env, on_0_1000 = TRUE, seedval = seed.val, temp_workdir = temp_workdir))
Expand Down

0 comments on commit 4cf9ef2

Please sign in to comment.