compile {rodeo}R Documentation

Generate Executable Code

Description

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

Arguments

sources

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.

fortran

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

target

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

lib

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.

reuse

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.

Value

invisible(NULL)

Note

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.

Author(s)

david.kneis@tu-dresden.de

See Also

This method internally calls generate.

Examples

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: 
model$compile(sources="functionsCode.f95")

## End(Not run)

[Package rodeo version 0.8.2 Index]