write_model: Export BUGS/JAGS model from function to file

View source: R/write_model.R

write_modelR Documentation

Export BUGS/JAGS model from function to file

Description

Performs the same basic function as R2OpenBUGS::write.model()

Usage

write_model(fun, file)

Arguments

fun

A function object containing BUGS/JAGS model code

file

A character vector of length == 1: the name of the file to write to

Details

Performs the same basic function as R2OpenBUGS::write.model(), but with slightly better output (scientific notation, spacing, etc.). The main reason it was created for use in 'postpack' was to remove the need for using the 'R2OpenBUGS' package when not using OpenBUGS.

Value

Nothing, but file is written to disk.

Examples

if (interactive()) {
  # define some simple BUGS model as an R function
  # note the use of %_% to include a truncation
  mod = function() {
    # PRIORS
    mu ~ dnorm(0,0.001) %_% T(0,)
    sig ~ dunif(0,10)
    tau <- 1/sig^2

    # LIKELIHOOD
    for (i in 1:n) {
      y[i] ~ dnorm(mu, tau)
    }
  }

  # write model to a text file to be called by BUGS/JAGS
  write_model(mod, "model.txt")
}

bstaton1/codaTools documentation built on Jan. 1, 2023, 12:17 p.m.