Dear Jamie and friends. I came up. with something that might be a useful idea to store the model results through a loop and remove the virtual memory through each iteration of the loop (Code at the bottom).
I have one question. I can store a big number of models this way, but I can not access interesting functions as eval.models() or eval.results() or evalplot.stats(). Is there any walkaround to make it possible to include all those individual models in one "ENMeval" object?
Thank you in advance
as an example
tune_rm_values <- c(0.5, 1, 3, 5, 10)
feature_combinations <- c("LQ", "LQH", "HC", "HQC", "TC", "LQHP")
combinations <- expand.grid(fc = feature_combinations, rm = tune_rm_values, stringsAsFactors = FALSE)
model_list <- list()
for (i in seq_len(total_combinations)) { # USE seq_len to avoid indexed problems
# Update progress bar
setTxtProgressBar(pb, i)
# set combinations of fc y rm
current_fc <- combinations$fc[i]
current_rm <- combinations$rm[i]
# Print the progress and the current execution (para depuración)
cat("Combination", i, "of", total_combinations, "- fc:", current_fc, ", rm:", current_rm, "\n")
# Define the settings for each loop
tune_args <- list(fc = current_fc, rm = current_rm)
# Execute ENMevaluate
model <- tryCatch({
ENMevaluate(
occs = occs[,c("longitude", "latitude")],
envs = clim.fit,
bg = bgs[,c("longitude", "latitude")],
algorithm = "maxent.jar",
partitions = 'block',
categoricals = "lancov",
progbar = F,
parallel = TRUE,
parallelType = "doParallel",
numCores = 8,
tune.args = tune_args
)
}, error = function(e) {
message(paste("Error on the combination fc =", current_fc, ", rm =", current_rm, ":", e$message))
return(NULL) # Return NULL in case of failure
})
# Store the result in a List object
gw_list[[paste0("fc_", current_fc, "_rm_", current_rm)]] <- model
# Eliminate the temporal object and free the memory
rm(model)
gc()
}