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.