R: Copying function for NIMBLE

nimCopy {nimble} | R Documentation

## Copying function for NIMBLE

### Description

Copies values from a NIMBLE model or modelValues object to another NIMBLE model or modelValues. Work in R and NIMBLE. The NIMBLE keyword `copy` is identical to `nimCopy`

### Usage

    nimCopy(from, to, nodes = NULL, nodesTo = NULL, row = NA, rowTo = NA,
      logProb = FALSE)

### Arguments

`from` | Either a NIMBLE model or modelValues object
`to` | Either a NIMBLE model or modelValues object
`nodes` | The nodes of object `from` which will be copied from
`nodesTo` | The nodes of object `to` which will be copied to. If `nodesTo == NA`, will automatically be set to `nodes`
`row` | If `from` is a modelValues, the row which will be copied from
`rowTo` | If `to` is a modelValues, the row which will be copied to. If `rowTo == NA`, will automatically be set to `row`
`logProb` | A logical value indicating whether the log probabilities of the given nodes should also be copied (i.e. if `nodes = 'x'` and `logProb = TRUE`, then both `'x'` and `'logProb_x'` will be copied)

### Details

See the User Manual for more details

### Author(s)

Clifford Anderson-Bergman

### Examples

    # Building model and modelValues object
    simpleModelCode <- nimbleCode({
    for(i in 1:100)
    	x[i] ~ dnorm(0,1)
    })
    rModel <- nimbleModel(simpleModelCode)
    rModelValues <- modelValues(rModel)

    #Setting model nodes
    rModel$x <- rnorm(100)
    #Using nimCopy in R.
    nimCopy(from = rModel, to = rModelValues, nodes = 'x', rowTo = 1)

    #Use of nimCopy in a simple nimbleFunction
    cCopyGen <- nimbleFunction(
    	setup = function(model, modelValues, nodeNames){},
    	run = function(){
    		nimCopy(from = model, to = modelValues, nodes = nodeNames, rowTo = 1)
    	}
    )

    rCopy <- cCopyGen(rModel, rModelValues, 'x')
    ## Not run:
    cModel <- compileNimble(rModel)
    cCopy <- compileNimble(rCopy, project = rModel)
    cModel[['x']] <- rnorm(100)

    cCopy$run() ## execute the copy with the compiled function

    ## End(Not run)

[Package nimble version 0.9.1 Index]