tests/testthat/test-jags.R

test_that("printing jags() output does not error if DIC is FALSE (#7)", {
  model <- "model {
    for (i in 1:n) {
      y[i] ~ dnorm(x[i] * beta, 1)
    }
    beta ~ dnorm(0, 1)
  }"
  tmp <- tempfile()
  writeLines(model, tmp)
  data <- list(
    n = 10,
    x = rnorm(10),
    y = rnorm(10)
  )
  library(coda)
  tmp <- utils::capture.output(
    out <- jags(
      data,
      parameters.to.save = "beta",
      model.file = tmp,
      n.chains = 4,
      DIC = FALSE,
      jags.module = character(0)
    )
  )
  expect_silent(tmp <- utils::capture.output(print(out)))
  expect_true(inherits(out, "rjags"))
})

Try the R2jags package in your browser

Any scripts or data that you put into this service are public.

R2jags documentation built on May 29, 2024, 11:47 a.m.