Skip to contents

This is the compilation workhorse creating the rxode2 model DLL files.

Usage

rxCompile(
  model,
  dir,
  prefix,
  force = FALSE,
  modName = NULL,
  package = NULL,
  ...
)

# S3 method for class 'rxModelVars'
rxCompile(
  model,
  dir = NULL,
  prefix = NULL,
  force = FALSE,
  modName = NULL,
  package = NULL,
  eventSensCode = rep("", 14L),
  ...
)

# S3 method for class 'character'
rxCompile(
  model,
  dir = NULL,
  prefix = NULL,
  force = FALSE,
  modName = NULL,
  package = NULL,
  eventSensCode = rep("", 14L),
  ...
)

# S3 method for class 'rxDll'
rxCompile(model, ...)

# S3 method for class 'rxode2'
rxCompile(model, ...)

Arguments

model

This is the ODE model specification. It can be:

  • a string containing the set of ordinary differential equations (ODE) and other expressions defining the changes in the dynamic system.

  • a file name where the ODE system equation is contained

An ODE expression enclosed in \{\}

(see also the filename argument). For details, see the sections “Details” and rxode2 Syntax below.

dir

This is the model directory where the C file will be stored for compiling.

If unspecified, the C code is stored in a temporary directory,
then the model is compiled and moved to the current directory.
Afterwards the C code is removed.

If specified, the C code is stored in the specified directory
and then compiled in that directory.  The C code is not removed
after the DLL is created in the same directory.  This can be
useful to debug the c-code outputs.

prefix

is a string indicating the prefix to use in the C based functions. If missing, it is calculated based on file name, or md5 of parsed model.

force

is a boolean stating if the (re)compile should be forced if rxode2 detects that the models are the same as already generated.

modName

a string to be used as the model name. This string is used for naming various aspects of the computations, including generating C symbol names, dynamic libraries, etc. Therefore, it is necessary that modName consists of simple ASCII alphanumeric characters starting with a letter.

package

Package name for pre-compiled binaries.

...

Other arguments sent to the rxTrans() function.

eventSensCode

character vector of length 14 giving the C body lines for the event ("jump") sensitivity helper functions dLag/dF/dRate/dDur/d2F/d2Lag/d2Rate/d2Dur/d3F/dFQ/ dLagJac/dLagQ/dDurQ/dMt (in that order). These are the per-model dosing-parameter total-derivative assignments produced by the event-sensitivity code generator and are emitted verbatim into the corresponding generated functions. The default of fourteen empty strings produces trivial (no-op) helpers, which is what non-sensitivity models and eventSens = "fd" models use.

Details

Background compiles are off by default. With options(rxode2.compile.async = TRUE), a caller can open a scope with the internal .rxCompileAsyncBegin() and close it with .rxCompileAsyncEnd(); inside it a model that needs a C compile is generated as usual but R CMD SHLIB runs in the background and rxCompile() returns at once. The library is joined (waited for, loaded, and checked against the model variables that were returned) at its first load or bind (a solve, rxDynLoad(), rxAssignPtr()), when the same model is compiled again, and at the end of the scope. options(rxode2.compile.jobs = n) sets how many builds run at once (default min(4, getRxThreads())); later ones queue. The libraries are the same files a synchronous build writes. A failed background build raises the same error and messages as a synchronous one, when it is joined.

Value

An rxDll object that has the following components

  • dll DLL path

  • model model specification

  • .c A function to call C code in the correct context from the DLL using the .C() function.

  • .call A function to call C code in the correct context from the DLL using the .Call() function.

  • args A list of the arguments used to create the rxDll object.

Author

Matthew L.Fidler

Examples

# \donttest{
mod <- function() {
  ini({
    k <- 0.1
  })
  model({
    d/dt(A) <- -k * A
  })
}
dll <- rxCompile(rxModelVars(mod()), dir = file.path(tempdir(), "rxCompile"))
dll
#> rxode2 DLL named "rx_b94d247e53e36d4aceeb5cb10d7bbde9_.so" is loaded and ready to use.
# }