From f20a9d81cbcd514ed629b69364cd85a72ac06e95 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 15 Apr 2023 08:41:37 +0200 Subject: Make using predefined symbols optional I got crashes under some circumstances when using symbols stored in the mkinmod object. One such circumstance was the use of a moved DLL in combination with parallel computing on a cluster. As I cannot exactly define at the moment when this happens, it is better to make this an opt in. --- R/mkinpredict.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'R') diff --git a/R/mkinpredict.R b/R/mkinpredict.R index 957d5793..8fa41217 100644 --- a/R/mkinpredict.R +++ b/R/mkinpredict.R @@ -27,6 +27,8 @@ #' When using compiled code, only lsoda is supported. #' @param use_compiled If set to \code{FALSE}, no compiled version of the #' [mkinmod] model is used, even if is present. +#' @param use_symbols If set to \code{TRUE}, symbol info present in the +#' [mkinmod] object is used if available for accessing compiled code #' @param atol Absolute error tolerance, passed to the ode solver. #' @param rtol Absolute error tolerance, passed to the ode solver. #' @param maxsteps Maximum number of steps, passed to the ode solver. @@ -114,6 +116,7 @@ mkinpredict.mkinmod <- function(x, outtimes = seq(0, 120, by = 0.1), solution_type = "deSolve", use_compiled = "auto", + use_symbols = FALSE, method.ode = "lsoda", atol = 1e-8, rtol = 1e-10, maxsteps = 20000L, map_output = TRUE, na_stop = TRUE, @@ -169,12 +172,18 @@ mkinpredict.mkinmod <- function(x, } if (solution_type == "deSolve") { - if (!is.null(x$cf) & !is.null(x$symbols) & use_compiled[1] != FALSE) { + if (!is.null(x$cf) & use_compiled[1] != FALSE) { + + if (!is.null(x$symbols) & use_symbols[1] == TRUE) { + lsoda_func <- x$symbols + } else { + lsoda_func <- "diffs" + } out <- deSolve::lsoda( y = odeini, times = outtimes, - func = x$symbols, + func = lsoda_func, initfunc = "initpar", dllname = x$dll_info[["name"]], parms = odeparms[x$parms], # Order matters when using compiled models -- cgit v1.2.1