Description Usage Arguments Details Value Author(s) Examples
Access or set a member variable of a specialized
nimbleFunction, i.e. a variable passed to or created during
the setup
function that is used in run code or
preserved by setupOutputs
. Works in R for any
variable and in NIMBLE for numeric variables.
1 | nfVar(nf, varName)
|
nf |
A specialized nimbleFunction, i.e. a function
returned by executing a function returned from
|
varName |
A character string naming a variable in
the |
When nimbleFunction
is called and a setup
function is provided, then nimbleFunction
returns a
function. That function is a generator that should be
called with arguments to the setup
function and
returns another function that will execute the run
function. The run
function and any other
methods
provided can use objects created or passed
to setup
. nfVar
provides direct access to
those objects by name.
In R, nfVar
can retrieve anything in setup
,
including models, other nimbleFunctions, and vectors of
node lists. In NIMBLE, it can only retrieve numeric
variables
For access to methods of nf
, see nfMethod
.
For more information, see ?nimbleFunction
and the
NIMBLE User Manual.
whatever varName is in the nimbleFunction nf.
NIMBLE development team
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | nfGen1 <- nimbleFunction(
setup = function(A) {
B <- matrix(rnorm(4), nrow = 2)
setupOutputs(B) ## preserves B even though it is not used in run-code
},
run = function() {
print('This is A', A, '\n')
})
nfGen2 <- nimbleFunction(
setup = function() {
nf1 <- nfGen1(1000)
},
run = function() {
print('accessing A:', nfVar(nf1, 'A'))
nfVar(nf1, 'B')[2,2] <<- -1000
print('accessing B:', nfVar(nf1, 'B'))
})
nf2 <- nfGen2()
nf2()
Cnf2 <- compileNimble(nf2)
Cnf2()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.