From c153cb1104d486f5155bda3281f0fc8face63cc9 Mon Sep 17 00:00:00 2001 From: Cole-Monnahan-NOAA Date: Wed, 25 Sep 2024 13:41:53 -0700 Subject: [PATCH] Update do.fit=FALSE to return list with report in it --- R/fimsfit.R | 14 ++++++++------ man/fit_fims.Rd | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/R/fimsfit.R b/R/fimsfit.R index aa0bbd4ab..e3bc89986 100644 --- a/R/fimsfit.R +++ b/R/fimsfit.R @@ -84,7 +84,8 @@ print.fimsfit <- function(fit, ...){ #' Hessian to do after optimization. #' @param control A list of optimizer settings passed to code{nlminb} #' @param getsd Calculate and return sdreport? -#' @param do.fit Optimize or return obj? Used for testing. +#' @param do.fit Optimize (TRUE, default) or (FALSE) build and return +#' a list containing the obj and report slot. #' @param save.sdrep Whether to return the sdreport object in the #' fitted model. This is rarely used and large so turned off by #' default. When returned it is named `sdrep`. @@ -93,10 +94,11 @@ print.fimsfit <- function(fit, ...){ #' and a value of NULL indicates not to save it. If specified, #' it must end in .RDS. The file is written to folder given by #' \code{input$path}. -#' @return A list object of class 'fimsfit' which contains a -#' "version" model name, rep, parList (MLE in list format), opt -#' as returned by \code{nlminb}, std (formatted data frame) and sdrep if -#' \code{getsd=TRUE}, and the obj. +#' @return If \code{do.fit} is TRUE then a list object of class 'fimsfit' +#' which contains a "version" model name, rep, parList (MLE in list format), +#' opt as returned by \code{nlminb}, std (formatted data frame) and sdrep if +#' \code{getsd=TRUE}, and the obj. If \code{do.fit} is FALSE then it returns +#' a list containing the TMB obj and rep slot for the report. #' @details This function is a beta version still and subject to change #' without warning. #' @export @@ -115,7 +117,7 @@ if (loopnum < 0) { obj <- MakeADFun(data=list(), parameters=input$parameters, map=input$map, random=input$random, DLL='FIMS', silent=TRUE) -if(!do.fit) return(obj) +if(!do.fit) return(list(obj=obj, rep=obj$report(obj$env$last.par.best))) # to do: max this update elements that are not supplied by default if(is.null(control)) control <- list(eval.max=10000, iter.max=10000, trace=0) diff --git a/man/fit_fims.Rd b/man/fit_fims.Rd index 1e8122a8d..7e432ab05 100644 --- a/man/fit_fims.Rd +++ b/man/fit_fims.Rd @@ -21,7 +21,8 @@ fit_fims( \item{getsd}{Calculate and return sdreport?} -\item{do.fit}{Optimize or return obj? Used for testing.} +\item{do.fit}{Optimize (TRUE, default) or (FALSE) build and return +a list containing the obj and report slot.} \item{newtonsteps}{The number of Newton steps using the inverse Hessian to do after optimization.} @@ -39,10 +40,11 @@ it must end in .RDS. The file is written to folder given by \code{input$path}.} } \value{ -A list object of class 'fimsfit' which contains a -"version" model name, rep, parList (MLE in list format), opt -as returned by \code{nlminb}, std (formatted data frame) and sdrep if -\code{getsd=TRUE}, and the obj. +If \code{do.fit} is TRUE then a list object of class 'fimsfit' +which contains a "version" model name, rep, parList (MLE in list format), +opt as returned by \code{nlminb}, std (formatted data frame) and sdrep if +\code{getsd=TRUE}, and the obj. If \code{do.fit} is FALSE then it returns +a list containing the TMB obj and rep slot for the report. } \description{ Fit a FIMS model (BETA)