aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/mkinfit.R14
-rw-r--r--R/mkinmod.R2
-rw-r--r--R/mkinpredict.R13
-rw-r--r--R/plot.mixed.mmkin.R10
-rw-r--r--R/plot.mkinfit.R5
-rw-r--r--R/saem.R8
6 files changed, 36 insertions, 16 deletions
diff --git a/R/mkinfit.R b/R/mkinfit.R
index b97bc7e2..c851fddb 100644
--- a/R/mkinfit.R
+++ b/R/mkinfit.R
@@ -501,10 +501,15 @@ mkinfit <- function(mkinmod, observed,
}
# Get native symbol before iterations info for speed
+ use_symbols = FALSE
if (solution_type == "deSolve" & use_compiled[1] != FALSE) {
- mkinmod[["symbols"]] <- deSolve::checkDLL(dllname = mkinmod$dll_info[["name"]],
- func = "diffs", initfunc = "initpar",
- jacfunc = NULL, nout = 0, outnames = NULL)
+ mkinmod[["symbols"]] <- try(
+ deSolve::checkDLL(dllname = mkinmod$dll_info[["name"]],
+ func = "diffs", initfunc = "initpar",
+ jacfunc = NULL, nout = 0, outnames = NULL))
+ if (!inherits(mkinmod[["symbols"]], "try-error")) {
+ use_symbols = TRUE
+ }
}
# Get the error model and the algorithm for fitting
@@ -616,8 +621,9 @@ mkinfit <- function(mkinmod, observed,
odeini, outtimes,
solution_type = solution_type,
use_compiled = use_compiled,
+ use_symbols = use_symbols,
method.ode = method.ode,
- atol = atol, rtol = rtol,
+ atol = atol, rtol = rtol,
...)
observed_index <- cbind(as.character(observed$time), as.character(observed$name))
diff --git a/R/mkinmod.R b/R/mkinmod.R
index 29542b71..2f930adb 100644
--- a/R/mkinmod.R
+++ b/R/mkinmod.R
@@ -464,11 +464,11 @@ mkinmod <- function(..., use_of_ff = "max", name = NULL,
silent = TRUE)
if (!inherits(model$cf, "try-error")) {
+ if (!quiet) message("Temporary DLL for differentials generated and loaded")
if (!is.null(dll_dir)) {
model$dll_info <- inline::moveDLL(model$cf, name, dll_dir,
unload = unload, overwrite = overwrite, verbose = !quiet)
}
- if (!quiet) message("Temporary DLL for differentials generated and loaded")
model$dll_info <- inline::getDynLib(model$cf)
}
}
diff --git a/R/mkinpredict.R b/R/mkinpredict.R
index 957d5793..60456fb2 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} (default), 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) {
+ 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
diff --git a/R/plot.mixed.mmkin.R b/R/plot.mixed.mmkin.R
index 466e55fc..d6c3d0de 100644
--- a/R/plot.mixed.mmkin.R
+++ b/R/plot.mixed.mmkin.R
@@ -166,10 +166,12 @@ plot.mixed.mmkin <- function(x,
}
}
- # Make sure degparms_pop is a matrix, columns corresponding to population curve(s)
- if (is.null(dim(degparms_pop))) {
- degparms_pop <- matrix(degparms_pop, ncol = 1,
- dimnames = list(names(degparms_pop), "Population"))
+ if (pop_curves) {
+ # Make sure degparms_pop is a matrix, columns corresponding to population curve(s)
+ if (is.null(dim(degparms_pop))) {
+ degparms_pop <- matrix(degparms_pop, ncol = 1,
+ dimnames = list(names(degparms_pop), "Population"))
+ }
}
degparms_fixed <- fit_1$fixed$value
diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R
index 9606507a..9f19213a 100644
--- a/R/plot.mkinfit.R
+++ b/R/plot.mkinfit.R
@@ -146,9 +146,8 @@ plot.mkinfit <- function(x, fit = x,
func = "diffs", initfunc = "initpar",
jacfunc = NULL, nout = 0, outnames = NULL)
}
- out <- try(mkinpredict(fit$mkinmod, odeparms, odeini, outtimes,
- solution_type = solution_type, atol = fit$atol, rtol = fit$rtol),
- silent = TRUE)
+ out <- mkinpredict(fit$mkinmod, odeparms, odeini, outtimes,
+ solution_type = solution_type, atol = fit$atol, rtol = fit$rtol)
out <- as.data.frame(out)
diff --git a/R/saem.R b/R/saem.R
index 2fa770bb..83de97b0 100644
--- a/R/saem.R
+++ b/R/saem.R
@@ -583,11 +583,15 @@ saemix_model <- function(object, solution_type = "auto",
transform_fractions <- object[[1]]$transform_fractions
# Get native symbol info for speed
+ use_symbols = FALSE
if (solution_type == "deSolve" & !is.null(mkin_model$cf)) {
- mkin_model$symbols <- deSolve::checkDLL(
+ mkin_model$symbols <- try(deSolve::checkDLL(
dllname = mkin_model$dll_info[["name"]],
func = "diffs", initfunc = "initpar",
- jacfunc = NULL, nout = 0, outnames = NULL)
+ jacfunc = NULL, nout = 0, outnames = NULL))
+ if (!inherits(mkin_model$symbols, "try-error")) {
+ use_symbols = TRUE
+ }
}
# Define the model function

Contact - Imprint