compile: Generate Executable Code

Description Arguments Value Note Author(s) See Also Examples


Creates and 'compiles' a function for use with numerical methods from package deSolve or rootSolve.



Name(s) of source files(s) where functions appearing in process rates or stoichiometric factors are implemented. Can be NULL if no external functions are required, the name of a single file, or a vector of file names. See notes below.


If TRUE, Fortran code is generated and compiled into a shared library. If FALSE, R code is generated.


Name of a 'target environment'. Currently, 'deSolve' is the only supported value.


File path to be used for the generated library (without the platform specific extension). Note that any uppercase characters will be converted to lowercase. By default, the file is created in R's temporary folder under a random name.


If TRUE, an already existing library file will be loaded. Use this to prevent unnecessary re-compilation but note that R is likely to crash in case of any mismatches between the object and the existing library. Default is FALSE, i.e. the library is unconditionally build from scratch.




The expected language of the external code passed in sources depends on the value of fortran.

If fortran is FALSE, R code is generated and made executable by eval and parse. Auxiliary code passed via sources is made available via source. The created R function is stored in the object.

If fortran is TRUE, the external code passed in sources must implement a module with the fixed name 'functions'. This module must contain all user-defined functions referenced in process rates or stoichiometric factors.

If fortran is TRUE, a shared library is created. The library is immediately loaded with dyn.load and it is automatically unloaded with dyn.unload when the object's finalize method is called.

The name of the library (base name without extension) as well as the name of the function to compute the derivatives are stored in the object. These names can be queried with the libName and libFunc methods, respectively. Unless a file path is specified via the lib argument, the library is created in the folder returned by tempdir under a unique random name.


See Also

This method internally calls generate.


data(vars, pars, funs, pros, stoi)
model <- rodeo$new(vars, pars, funs, pros, stoi, dim=c(1))
# This would trigger compilation assuming that 'functionsCode.f95' contains
# a Fortran implementation of all functions; see vignette for full example
## Not run: 

## End(Not run)

rodeo documentation built on March 28, 2021, 1:09 a.m.