Description Usage Arguments Details Author(s) Examples
Explicitly declare a variable in run-time code of a nimbleFunction, for cases when its dimensions cannot be inferred before it is used. Works in R and NIMBLE.
1 |
name |
Name of a variable to declare, without quotes |
def |
NIMBLE type declaration, of the form
|
In a run-time function of a nimbleFunction (either the
run
function or a function provided in
methods
when calling nimbleFunction
), the
dimensionality and numeric type of a variable is inferred
when possible from the statement first assigning into it.
E.g. A <- B + C
infers that A
has numeric
types, dimensions and sizes taken from B + C
.
However, if the first appearance of A
is e.g.
A[i] <- 5
, A
must have been explicitly
declared. In this case, declare(A, double(1))
would
make A
a 1-dimensional (i.e. vector) double.
When sizes are not set, they can be set by a call to
setSize
or by assignment to the whole object. Sizes
are not automatically extended if assignment is made to
elements beyond the current sizes. In compiled
nimbleFunctions doing so can cause a segfault and crash the
R session.
This part of the NIMBLE language is needed for compilation,
but it also runs in R. When run in R, is works by the side
effect of creating or modifying name
in the calling
environment.
NIMBLE development team
1 2 3 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.