nlmixr2save 0.2.0
CRAN release: 2026-08-04
loadFit()(and therefore:=) now restores the fit table’sIDcolumn as a factor. The table round-trips through a plain.csv, soIDcame back as an integer while a live fit carries a factor; anything joining the fit table to something derived from the fit then hit a type mismatch, sincenlme::augPred()keeps itsida factor.ggPMX::pmx_nlmixr()on a cached fit failed outright with “Incompatible join types: x.ID (factor) and i.ID (integer)”. The repair happens on load, so caches written by earlier versions are fixed too.saveFit()now records theparHistData$typefactor levels for fits that storeparHistDatacompressed (the nlmixr2est default). It read the levels straight out of the fit environment, where a compressed fit keeps a raw vector rather than a data frame, so the levels were silently not recorded andloadFit()fell back to a hardcoded level list. nlmixr2est has since added types that list predates (“Analytic Gradient (relaxed)” and friends), and those came back asNA.loadFit()now repairs aparHistData$typethat the cache’s own restore script dropped toNA. Those levels are applied by the script stored inside the cache, so a cache written before nlmixr2est added a type has no level for it and coerces it toNA– and re-saving cannot recover it, because by then the string is already gone.loadFit()reads the column back from the-parHistData.csvin the cache and appends whatever the script was missing, so existing caches are repaired in place.Saving or loading a fit no longer disturbs another cache whose base name it is a suffix of. The list of files belonging to a fit was matched with an unanchored pattern, so a cache named
fitalso matchedmyfit-env.R– zipping another cache’s files into its own archive and then deleting them from disk. This is reachable whenever unzipped files are lying around, whichsaveFit(zip=FALSE)leaves by design. The names are now matched literally rather than as a regexp, so a base name holding a metacharacter (my.fitis an ordinary R name, and as a pattern its.also matchedmy_fit) is matched exactly.saveFit(fit, zip=FALSE)now actually leaves the fit unzipped for a fit table (anlmixr2FitData). The method wrote the fit.csvand then called the core method with a hardcodedzip=TRUE, so the argument was silently ignored for every fit that carries data.nlmixrDataSimplify()gainedestandcontrolarguments and no longer drops the covariate columns thatest="vae"searches for. The VAE covariate search picks its covariates out of the data instead of out of the model, so the candidate columns (as identified bynlmixr2est::vaeCovariates(), matched to thevaeControl()search options) are now kept in the simplified data and included in the hash. When the installednlmixr2estdoes not exportvaeCovariates()the search is skipped rather than erroring.-
You can now export a fit without the original data so a fitted model can be shared when the subject-level data cannot:
-
saveFit(fit, data = FALSE)(oroptions(nlmixr2save.data = FALSE)) writes a fit whoseorigDatais omitted from the zip. - New
nlmixr2saveShare()strips an existing saved fit (a live object or a.zipbase name; honorsnlmixr2save.dir/nlmixr2save.prefix) into a shareable sibling zip:fit-noData.zip(data removed) or, withnoFit = TRUE,fit-noData-noFit.zip(data and the returned prediction/residual table removed, keeping the model, estimates, eta table and parameter history). The original fit is left unchanged.
See
vignette("sharing-fits"), which also documents the side effects (e.g. VPC, residual re-derivation, and re-fitting need the original data). -
saveFit()no longer stores the redundantmodelelement (the loader always rebuilds it fromui). This removes a spurious “could not determine how to save object of class call for item model” warning when re-saving a previously loaded fit (including vianlmixr2saveShare()).-
Saved fits now record the
nlmixr2estandrxode2versions they were produced with (including each package’s commit sha when it was installed from a remote such as GitHub). When a fit is later loaded and the installednlmixr2estorrxode2differs:-
loadFit()warns that the fit was run with a different package version (controllable with the newcheckVersionargument). - the
:=caching operator, in an interactive session, asks whether to rerun the fit with the currently installed packages; non-interactively it loads the cached fit and warns. (Trusted-cache mode,nlmixr2save.check = FALSE, is left untouched so committed caches stay stable across versions.)
Fits saved by older
nlmixr2saveversions (which carry no version metadata) continue to load without any warning. The whole check can be turned off withoptions(nlmixr2save.checkVersion = FALSE)(or per call vialoadFit(..., checkVersion = FALSE)); it isTRUEby default. Seevignette("version-tracking"). -
The
parHistData$typefactor levels are now recorded from the fit at save time and restored on load, so the factor round-trips correctly regardless of whichnlmixr2estversion produced it (the level set has grown over versions, e.g."Analytic Gradient"). A hardcoded fallback covers fits saved before this was recorded.-
The
:=caching operator gains threeoptions()(mirroringnlmixr2save.quiet):-
nlmixr2save.prefix(default""): prepended to the assigned variable name to form the cache file, e.g. withoptions(nlmixr2save.prefix = "modelPiping-"),fit := nlmixr2(...)caches tomodelPiping-fit.zip. -
nlmixr2save.dir(default"."): the directory the cache files live in. -
nlmixr2save.check(defaultTRUE): whenTRUE,:=keeps verifying the cache against the current model/data/arguments (historical behavior); whenFALSE,:=simply loads the cache file if it exists (a fit as.zip, a simulation/other value as.rds) and otherwise runs and saves it – the cache is trusted and regenerated only when missing. This keeps a committed cache stable across nlmixr2/rxode2 versions.
-
New
nlmixr2saveInvalidate(): deletes every:=cache entry under the activenlmixr2save.prefix/nlmixr2save.dir, so cached fits/simulations are re-run on the next render whennlmixr2save.checkisFALSE.The saved-fit loader script now quotes its variable name, so a
nlmixr2save.prefixcontaining non-syntactic characters (e.g.-) round-trips correctly.Support both
$parFixedDfstructures produced by nlmixr2est: the current one (named “Estimate”/“SE” columns) and the upcoming$parFixedrefactor (nlmixr2est#645, unnamed columns). The structure of the fit is detected when it is saved and recorded in the restore script, so fits round-trip exactly with either version (nlmixr2saveParFixedDf()gained anamedargument; existing saved zip files continue to load unchanged).Additional all-
NAnumeric columns of$parFixedDf(for example “CI Lower”/“CI Upper” when there is no covariance step) are now coerced back to numeric when a saved fit is loaded, instead of being left as logical columns from the CSV round-trip.
nlmixr2save 0.1.0
CRAN release: 2026-06-17
Create zip files that are (mostly) R independent to save nlmixr2 fit items
Create a cached assignment operator
:=to save nlmixr2 fits automatically; if used, it will load a cached fit if function arguments are the same (a sort of disk memoization of the outermost function)Initial CRAN submission.
