Learn R Programming

nimble (version 1.4.0)

nimbleCode: Turn BUGS model code into an object for use in nimbleModel or readBUGSmodel

Description

Takes one or more R expressions or code objects, combines them if necessary, and returns the resulting code as an R call object in the form needed by nimbleModel and optionally usable by readBUGSmodel.

Usage

nimbleCode(...)

Arguments

...

One or more R code expressions or objects containing R code, providing the code for the model. See details.

Author

Daniel Turek and Ken Kellner

Details

You may provide code to nimbleCode in two ways. The first way is to provide the code as an argument directly, wrapped in curly brackets ({}). The second is to create an object containing code with either nimbleCode or quote, and pass that object to nimbleCode. You may mix and match these two approaches. Note that code provided directly but not wrapped in {} will be rejected. When multiple pieces of code are provided as arguments, they will be combined into a single code object by nimbleCode and unnecessary curly brackets will be automatically removed.

When providing a single block of code directly, the result from nimbleCode is equivalent to using the R function quote. nimbleCode is simply provided as a more readable alternative for NIMBLE users not familiar with quote.

Examples

Run this code
# Provide a single block of code directly
code <- nimbleCode({
    x ~ dnorm(mu, sd = 1)
    mu ~ dnorm(0, sd = prior_sd)
})

code_new <- nimbleCode({
    prior_sd ~ dhalfflat()
})

# Combine multiple previously saved code objects
code2 <- nimbleCode(code, code_new)

# Combine code and previously saved code objects
code3 <- nimbleCode({
   y ~ dnorm(mu, sd = 1)
}, code, code_new)

Run the code above in your browser using DataLab