From 3529f5ff498d7d054c7b1911ddfc4b242902b85d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 28 Sep 2022 16:34:57 +0200 Subject: Fix handling of multistart fits with failures --- R/multistart.R | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'R/multistart.R') diff --git a/R/multistart.R b/R/multistart.R index cc55feae..b65c0bee 100644 --- a/R/multistart.R +++ b/R/multistart.R @@ -92,15 +92,51 @@ multistart.saem.mmkin <- function(object, n = 50, cores = 1, return(res) } -#' @rdname multistart #' @export -print.multistart <- function(x, ...) { - cat("Multistart object with", length(x), "fits of the following type:\n\n") - print(x[[1]]) +convergence.multistart <- function(object, ...) { + all_summary_warnings <- character() + + result <- lapply(object, + function(fit) { + if (inherits(fit, "try-error")) return("E") + else { + return("OK") + } + }) + result <- unlist(result) + + class(result) <- "convergence.multistart" + return(result) +} + +#' @export +convergence.multistart.saem.mmkin <- function(object, ...) { + all_summary_warnings <- character() + + result <- lapply(object, + function(fit) { + if (inherits(fit$so, "try-error")) return("E") + else { + return("OK") + } + }) + result <- unlist(result) + + class(result) <- "convergence.multistart" + return(result) +} + +#' @export +print.convergence.multistart <- function(x, ...) { + class(x) <- NULL + print(table(x, dnn = NULL)) + if (any(x == "OK")) cat("OK: Fit terminated successfully\n") + if (any(x == "E")) cat("E: Error\n") } #' @rdname multistart #' @export -parms.multistart <- function(object, ...) { - t(sapply(object, parms)) +print.multistart <- function(x, ...) { + cat(" object with", length(x), "fits:\n") + print(convergence(x)) } -- cgit v1.2.1