Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Imports:
graphics,
grDevices,
parallel,
rjags (>= 3-13),
rjags (>= 4-17),
stats,
utils
Suggests: knitr, markdown, tinytest
Expand Down
8 changes: 7 additions & 1 deletion R/run_rjags.R
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,13 @@ set.factories <- function(factories){
set.modules <- function(modules,DIC){

#Load/unload appropriate modules (besides dic)
called.set <- c('basemod','bugs',modules)

default.set <- c('basemod', 'bugs')
if (rjags::jags.version() >= as.numeric_version("5")) {
#deviance monitor moved to the 'diag' module so load by default
default.set <- c(default.set, 'diag')
}
called.set <- c(default.set, modules)
current.set <- rjags::list.modules()

load.set <- called.set[!called.set%in%current.set]
Expand Down
17 changes: 13 additions & 4 deletions inst/tinytest/test_autojags.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ nul <- capture.output(

# Runs three updates of 10 iterations each
expect_true(grepl("Note: ALL iterations", nul[6]))
expect_true(grepl("Update 3", nul[10]))
expect_true(nul[11] == "")
# All are combined to yield 30 total iterations in each chain
expect_equal(coda::niter(out$samples), 30)
if (rjags::jags.version() >= as.numeric_version("5")) {
expect_true(grepl("Update 2", nul[9]))
expect_true(nul[10] == "")
# All are combined to yield 20 total iterations in each chain
expect_equal(coda::niter(out$samples), 20)

} else {
expect_true(grepl("Update 3", nul[10]))
expect_true(nul[11] == "")
# All are combined to yield 30 total iterations in each chain
expect_equal(coda::niter(out$samples), 30)
}


if(at_home){
ref <- readRDS("autojags_ref_alliter.Rds")
Expand Down
30 changes: 18 additions & 12 deletions inst/tinytest/test_run_rjags.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# load_modules loads and unloads correctly

if (rjags::jags.version() < as.numeric_version("5")) {
default.modules <- c('basemod','bugs')
test.factories <- 1:2
} else {
default.modules <- c('basemod','bugs','diag') # diag provides deviance monitor
test.factories <- c(6,1) # change in precedence of bugs::binomSlice factory
}

jagsUI:::set.modules(NULL, FALSE)
expect_equal(rjags::list.modules(),c('basemod','bugs'))
expect_equal(rjags::list.modules(),default.modules)
jagsUI:::set.modules('glm', FALSE)
expect_equal(rjags::list.modules(),c('basemod','bugs','glm'))
expect_equal(rjags::list.modules(),c(default.modules,'glm'))
jagsUI:::set.modules(NULL, FALSE)
expect_equal(rjags::list.modules(),c('basemod','bugs'))
expect_equal(rjags::list.modules(),default.modules)
jagsUI:::set.modules(NULL, DIC=TRUE)
expect_equal(rjags::list.modules(),c('basemod','bugs','dic'))

expect_equal(rjags::list.modules(),c(default.modules,'dic'))

# load_factories works correctly
jagsUI:::set.factories(NULL)
expect_equal(rjags::list.factories('sampler')[1:2,2], c(TRUE, TRUE))
jagsUI:::set.factories(c('bugs::BinomSlice sampler FALSE',
'bugs::RW1 sampler FALSE'))
expect_equal(rjags::list.factories('sampler')[1:2,2], c(FALSE, FALSE))
jagsUI:::set.factories(c('bugs::BinomSlice sampler TRUE',
'bugs::RW1 sampler TRUE'))
expect_equal(rjags::list.factories('sampler')[1:2,2], c(TRUE, TRUE))
expect_equal(rjags::list.factories('sampler')[test.factories,2], c(TRUE, TRUE))
jagsUI:::set.factories(c('bugs::BinomSlice sampler FALSE', 'bugs::RW1 sampler FALSE'))
expect_equal(rjags::list.factories('sampler')[test.factories,2], c(FALSE, FALSE))
jagsUI:::set.factories(c('bugs::BinomSlice sampler TRUE', 'bugs::RW1 sampler TRUE'))
expect_equal(rjags::list.factories('sampler')[test.factories,2], c(TRUE, TRUE))
expect_error(jagsUI:::set.factories(c('bad bad')))
expect_error(jagsUI:::set.factories(c('bugs::fake sampler FALSE')))
Loading