Skip to contents

Compile an odin model, yielding a dust_system_generator object.

Usage

odin(
  expr,
  input_type = NULL,
  quiet = NULL,
  workdir = NULL,
  debug = NULL,
  skip_cache = FALSE,
  compatibility = "warning"
)

Arguments

expr

Odin code as the path to a file (a string), a character vector of code, or as an expression (typically within braces {}).

input_type

An optional string describing the type of input for expr - must be one of file, text or expression. If given, this skips the type detection logic and odin will throw an error if the wrong type of input is given. Using this may be beneficial in programmatic environments.

quiet

Logical, indicating if compilation messages from pkgbuild should be displayed. Error messages will be displayed on compilation failure regardless of the value used. If NULL is given, then we take the value from DUST_QUIET if set, or FALSE otherwise.

workdir

Optional working directory to use. If NULL, the behaviour depends on the existence of the environment variable DUST_WORKDIR_ROOT. If it is unset we use a session-specific temporary directory (generated by tempfile()). If DUST_WORKDIR_ROOT is set, then we use a stable generated filename within this directory, which allows different sessions to effectively share a cache. If you pass a directory name here as a string, then we will use that directory to write all code, which allows you to inspect the generated code. See vignette("details") for more information.

debug

Passed to pkgbuild::compile_dll, this will build a debug library. If NULL is given, then we take the value from DUST_DEBUG if set, or FALSE otherwise.

skip_cache

Logical, indicating if the cache of previously compiled systems should be skipped. If TRUE then your system will not be looked for in the cache, nor will it be added to the cache after compilation.

compatibility

Compatibility mode to use. Valid options are "warning", which updates code that can be fixed, with warnings, and "error", which will error. The option "silent" will silently rewrite code, but this is not recommended for general use as eventually the compatibility mode will be removed (this option is primarily intended for comparing output of odin1 and odin2 models against old code).

Value

A dust_system_generator object, suitable for using with dust functions (starting from dust2::dust_system_create)

Examples

if (FALSE) { # interactive()
# A random walk:
gen <- odin({
  initial(x) <- 0
  update(x) <- Normal(x, 1)
})

sys <- dust2::dust_system_create(gen, list(), n_particles = 10)
y <- dust2::dust_system_simulate(sys, 0:100)
matplot(t(y[1, , ]), type = "l", lty = 1, xlab = "Time", ylab = "Value")
}