nimbleOptions(enableModelMacros = TRUE)
nimbleOptions(enableMacroComments = FALSE)
nimbleOptions(verbose = FALSE)
testMacro <- list(process = function(code, modelInfo, .env){
code <- quote({
for (i_ in 1:n){
mu[i_] <- alpha + beta
y[i_] ~ dnorm(0, sigma)
}
alpha ~ dnorm(0, 1)
})
list(code = code, modelInfo=modelInfo)
})
class(testMacro) <- "model_macro"
code <- nimbleCode({
y[1:n] ~ testMacro()
})
const <- list(y = rnorm(10), n = 10)
mod <- nimbleModel(code, constants=const)
mod$getMacroParameters()
# should be list(testMacro = list(c("mu", "alpha", "beta", "sigma")))
mod$getMacroParameters(includeRHS = FALSE)
# should be list(testMacro = list(c("mu", "alpha")))
Run the code above in your browser using DataLab