Skip to contents

By default it is equivalent to the standard assignment operator <-, but it is a S3 generic so it can have other behaviors for specific classes.

Arguments

x

the name of the object to assign the value to

value

the value to assign to the object, because R can use non-standard evaluation, this expression may not be evaluated when passed to the function. In the case of the nlmixr2 function, the expression will be evaluated only if the fit needs to be refit (i.e. if the zip file does not exist or if the sha1 hash of the arguments does not match).

Value

the value that was assigned to the object, invisibly. It also has the side effect of assigning the value to the parent environment.

Details

For example, when used with a nlmixr2 call, say:

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

the := operator will assign the result of the nlmixr2 call to fit, but it will also save the fit to a file named "fit.zip" in the current working directory.

If the "fit.zip" file already exists, it will be loaded instead of running the possibly expensive fitting process (as long as the sha1 hash of the arguments are the same).

This allows for easy saving and loading of fitted models without having to explicitly call a save function.

This S3 generic can be extended to other classes as needed, allowing for custom behaviors when assigning values to objects of those classes.

When trying to save expensive evaluations like the output of a nlmixr2() fit, the s3 dispach would be to :=.assign_nlmixr2(x, value) or whatever function is used in the call. This allows checking the arguments to see if there can be a cache that will be loaded.

Otherwise, the default s3 method would be :=.class where class instead. Unlike the un-evaluated function dispach there is no way to check the arguments for a cache, so loading from cache is not possible.

See also

saveFit() for saving fitted model objects to files, loadFit() for loading fitted model objects from files, and .assignParent() for getting or setting the environment used in the := operator.

Author

Matthew L. Fidler

Examples


# \donttest{
 if (requireNamespace("nlmixr2est", 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)
       })
    }
    # First fit creates fit.zip
    fit := nlmixr2(one.cmt, theo_sd, est="focei")

    # Second fit loads from fit.zip since it had the same options
    fit := nlmixr2(one.cmt, theo_sd, est="focei")

    # Third fit refits since the options are different
    fit := nlmixr2(one.cmt, theo_sd, est="saem")
  })
 }
#> Loading required package: nlmixr2data
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  
#>  
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of full model...
#>  done
#> → calculate jacobian
#> → calculate ∂(f)/∂(η)
#> → calculate ∂(R²)/∂(η)
#> → finding duplicate expressions in inner model...
#> → optimizing duplicate expressions in inner model...
#> → finding duplicate expressions in EBE model...
#> → optimizing duplicate expressions in EBE model...
#> → compiling inner model...
#>  
#>  
#>  done
#> → finding duplicate expressions in FD model...
#> → compiling EBE model...
#>  
#>  
#>  done
#> → compiling events FD model...
#>  
#>  
#>  done
#> rxode2 5.1.0 using 2 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
#> 
#> Attaching package: ‘rxode2’
#> The following objects are masked from ‘package:nlmixr2est’:
#> 
#>     boxCox, yeoJohnson
#> → Calculating residuals/tables
#>  done
#>  saving fit item: .rownum
#>  saving fit item: AIC
#>  saving fit item: BIC
#>  saving fit item: R
#>  saving fit item: R.0
#>  saving fit item: R.E
#>  saving fit item: R.pd
#>  saving fit item: Rinv
#>  saving fit item: S
#>  saving fit item: S.E
#>  saving fit item: S.pd
#>  saving fit item: S0
#>  saving fit item: Sper
#>  saving fit item: aqHi
#>  saving fit item: aqLow
#>  saving fit item: aqn
#>  saving fit item: censInformation
#>  saving fit item: cholR
#>  saving fit item: cholS
#>  saving fit item: conditionNumberCor
#>  saving fit item: conditionNumberCov
#>  saving fit item: convergence
#>  saving fit item: cov
#>  saving fit item: covLvl
#>  saving fit item: covMethod
#>  saving fit item: covR
#>  saving fit item: covRS
#>  saving fit item: covS
#>  saving fit item: eigenCor
#>  saving fit item: eigenCov
#>  saving fit item: eigenVecCor
#>  saving fit item: eigenVecCov
#>  saving fit item: est
#>  saving fit item: etaObf
#>  saving fit item: extra
#>  saving fit item: fixef
#>  saving fit item: foceiControl0
#>  saving fit item: foceiModel
#>  saving fit item: fullCor
#>  saving fit item: iniDf0
#>  saving fit item: llikObs
#>  saving fit item: logLik
#>  saving fit item: message
#>  saving fit item: method
#>  saving fit item: mixIdx
#>  saving fit item: nAGQ
#>  saving fit item: nEstOmega
#>  saving fit item: nlmixr2save
#>  saving fit item: nlmixr2saveOrig
#>  saving fit item: nobs
#>  saving fit item: nsub
#>  saving fit item: objDf
#>  saving fit item: objective
#>  saving fit item: ofvType
#>  saving fit item: omega
#>  saving fit item: optReturn
#>  saving fit item: origData
#>  saving fit item: parFixed
#>  saving fit item: parFixedDf
#>  saving fit item: parHistData
#>  saving fit item: phiC
#>  saving fit item: phiH
#>  saving fit item: qfirst
#>  saving fit item: qw
#>  saving fit item: qx
#>  saving fit item: ranef
#>  saving fit item: runInfo
#>  saving fit item: scaleInfo
#>  saving fit item: sessioninfo
#>  saving fit item: shrink
#>  saving fit item: table
#>  saving fit item: time
#>  saving fit item: tolFactor
#>  saving fit item: ui
#>  zipping fit files
#>  removing unzipped fit files
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  loading fit from fit.R
#>  
#>  
#>  
#>  
#>  
#>  
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  removing unzipped fit files
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  loading fit from fit.R
#>  
#>  
#>  
#>  
#>  
#>  
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  removing unzipped fit files
#>  fit in fit.zip does not match current fit; removing and refitting
#>  
#>  
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  
#>  
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#>  done
#> → finding duplicate expressions in saem model...
#>  done
#>  calculate uninformed etas
#>  done
#> params:	tka	rxBoundedTr.tcl	tv	V(eta.ka)	V(eta.v)	V(eta.cl)	add.sd
#> Calculating covariance matrix
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#>  done
#> → finding duplicate expressions in saem predOnly model 0...
#> → finding duplicate expressions in saem predOnly model 1...
#> → finding duplicate expressions in saem predOnly model 2...
#> → optimizing duplicate expressions in saem predOnly model 2...
#>  done
#>  
#>  
#> → Calculating residuals/tables
#>  done
#> → compress origData in nlmixr2 object, save 6584
#> → compress parHistData in nlmixr2 object, save 8296
#> → compress phiM in nlmixr2 object, save 429424
#>  saving fit item: .likTime
#>  saving fit item: .rownum
#>  saving fit item: AIC
#>  saving fit item: BIC
#>  saving fit item: adjObf
#>  saving fit item: aqHi
#>  saving fit item: aqLow
#>  saving fit item: aqn
#>  saving fit item: censInformation
#>  saving fit item: conditionNumberCor
#>  saving fit item: conditionNumberCov
#>  saving fit item: cov
#>  saving fit item: covLvl
#>  saving fit item: covMethod
#>  saving fit item: eigenCor
#>  saving fit item: eigenCov
#>  saving fit item: eigenVecCor
#>  saving fit item: eigenVecCov
#>  saving fit item: est
#>  saving fit item: etaObf
#>  saving fit item: extra
#>  saving fit item: fixef
#>  saving fit item: foceiControl0
#>  saving fit item: fullCor
#>  saving fit item: iniDf0
#>  saving fit item: logLik
#>  saving fit item: message
#>  saving fit item: method
#>  saving fit item: mixIdx
#>  saving fit item: nAGQ
#>  saving fit item: nEstOmega
#>  saving fit item: nlmixr2save
#>  saving fit item: nlmixr2saveOrig
#>  saving fit item: nobs
#>  saving fit item: nsub
#>  saving fit item: objDf
#>  saving fit item: objective
#>  saving fit item: ofvType
#>  saving fit item: omega
#>  saving fit item: origData
#>  saving fit item: parFixed
#>  saving fit item: parFixedDf
#>  saving fit item: parHistData
#>  saving fit item: phiM
#>  saving fit item: qfirst
#>  saving fit item: qw
#>  saving fit item: qx
#>  saving fit item: ranef
#>  saving fit item: runInfo
#>  saving fit item: saem0
#>  saving fit item: saemControl
#>  saving fit item: saemModel
#>  saving fit item: scaleInfo
#>  saving fit item: sessioninfo
#>  saving fit item: shrink
#>  saving fit item: table
#>  saving fit item: time
#>  saving fit item: tolFactor
#>  saving fit item: ui
#>  zipping fit files
#>  removing unzipped fit files
# }