Skip to contents

Formats a BUGS model string to Julia's `@bugs("""...""", convert_var_name, true)` syntax, used in the Julia ecosystem for running BUGS models. By default, this macro converts R-style variable names (e.g., `a.b.c`) to Julia-style (`a_b_c`). You can disable this behavior by setting `convert_var_name = FALSE`.

Usage

bugs2juliaBUGS(model_code, convert_var_name = TRUE)

Arguments

model_code

A character string containing the BUGS model.

convert_var_name

Logical; if `TRUE` (default), R-style variable names such as `a.b.c` are translated to `a_b_c` in the Julia model. Set to `FALSE` to preserve original names.

Value

A character string formatted as a Julia `@bugs` macro call.

Examples

model <- "
  for i in 1:N
    y[i] ~ dnorm(mu, tau)
  end
  mu ~ dnorm(0.0, 1.0E-6)
  tau ~ dgamma(0.001, 0.001)
"
bugs2juliaBUGS(model)
#> [1] "model = @bugs(\"\"\"\nfor i in 1:N\n    y[i] ~ dnorm(mu, tau)\n  end\n  mu ~ dnorm(0.0, 1.0E-6)\n  tau ~ dgamma(0.001, 0.001)\n\"\"\", true, true)"
bugs2juliaBUGS(model, convert_var_name = FALSE)
#> [1] "model = @bugs(\"\"\"\nfor i in 1:N\n    y[i] ~ dnorm(mu, tau)\n  end\n  mu ~ dnorm(0.0, 1.0E-6)\n  tau ~ dgamma(0.001, 0.001)\n\"\"\", false, true)"