saveFit: Save a fitted model object to a series of files

View source: R/save.R

saveFitR Documentation

Save a fitted model object to a series of files

Description

Save a fitted model object to a series of files

Usage

saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

## S3 method for class 'nlmixr2FitCore'
saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

## S3 method for class 'nlmixr2FitData'
saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

## Default S3 method:
saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

Arguments

fit

the fitted model object

file

the base name of the files to save the fit to. It may include a directory, e.g. "path/to/fit": the files are written there (the directory is created if needed) and the archive path/to/fit.zip holds them under the bare name fit, so it can be moved and loaded from anywhere.

zip

Boolean indicating if the files should be zipped.

data

Boolean indicating whether the original dataset (origData) is stored in the saved fit. When FALSE it is omitted, producing a fit that can be shared without the subject-level data (see nlmixr2saveShare()). Defaults to getOption("nlmixr2save.data", TRUE).

Value

nothing, called for side effects

Author(s)

Matthew L. Fidler

Examples


  if (requireNamespace("nlmixr2est", quietly=TRUE) &&
        requireNamespace("nlmixr2data", quietly=TRUE) &&
        requireNamespace("withr")) {
    library(nlmixr2est)
    library(nlmixr2data)
    withr::with_tempdir({
      one.cmt <- function() {
        ini({
          tka <- 0.45
          tcl <- log(c(0, 2.7, 100))
          tv <- 3.45
          eta.ka ~ 0.6
          eta.cl ~ 0.3
          eta.v ~ 0.1
          add.sd <- 0.7
        })
        model({
          ka <- exp(tka + eta.ka)
          cl <- exp(tcl + eta.cl)
          v  <- exp(tv + eta.v)
          linCmt() ~ add(add.sd)
        })
      }

      fit <- nlmixr2(one.cmt, theo_sd, est="focei")

      saveFit(fit) # saved to fit.zip
      fit2 <- loadFit(fit) # load fit.zip

      if (file.exists("fit.zip")) {
         unlink("fit.zip")
      }

      print(fit2)
    })
  }


nlmixr2save documentation built on Sept. 26, 2026, 1:07 a.m.