nfVar: Access or set a member variable of a nimbleFunction created...

Description Usage Arguments Details Value Author(s) Examples

Description

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.

Usage

1
nfVar(nf, varName)

Arguments

nf

A specialized nimbleFunction, i.e. a function returned by executing a function returned from nimbleFunction with setup arguments

varName

A character string naming a variable in the setup function.

Details

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.

Value

whatever varName is in the nimbleFunction nf.

Author(s)

NIMBLE development team

Examples

 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()

thirdwing/nimble documentation built on May 31, 2019, 10:41 a.m.