From b66c860769ca538c0995ca57521d20507cdd3b78 Mon Sep 17 00:00:00 2001 From: Ken Kellner Date: Tue, 23 Jan 2024 14:36:25 -0500 Subject: Fix tests on Windows --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- inst/tinytest/test_autojags.R | 10 +++++----- inst/tinytest/test_jags.R | 18 +++++++++--------- inst/tinytest/test_jagsbasic.R | 14 +++++++------- inst/tinytest/test_update.R | 10 +++++----- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 729fb2a..a7f43ca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: jagsUI -Version: 1.6.0 -Date: 2024-01-21 +Version: 1.6.1 +Date: 2024-01-23 Title: A Wrapper Around 'rjags' to Streamline 'JAGS' Analyses Authors@R: c( person("Ken", "Kellner", email="contact@kenkellner.com", role=c("cre","aut")), diff --git a/NEWS.md b/NEWS.md index 3f936d0..1e3b04f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# jagsUI 1.6.0 +# jagsUI 1.6.1 * Extensive refactoring of internal code * Don't drop output dimensions when only one parameter saved diff --git a/inst/tinytest/test_autojags.R b/inst/tinytest/test_autojags.R index 5753cc8..e06c75e 100644 --- a/inst/tinytest/test_autojags.R +++ b/inst/tinytest/test_autojags.R @@ -29,7 +29,7 @@ ref <- readRDS("autojags_ref.Rds") # Remove time/date based elements out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(17,18,21)], ref[-c(17,18,21)]) +expect_equal(out[-c(17,18,21)], ref[-c(17,18,21)]) # codaOnly--------------------------------------------------------------------- @@ -41,7 +41,7 @@ ref <- readRDS("autojags_ref_codaonly.Rds") # Remove time/date based elements out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(17,18,21)], ref[-c(17,18,21)]) +expect_equal(out[-c(17,18,21)], ref[-c(17,18,21)]) # Check recovery after process_output errors----------------------------------- # Setting DIC to -999 forces process_output to error for testing @@ -71,7 +71,7 @@ expect_true(nul[11] == "") expect_equal(coda::niter(out$samples), 30) ref <- readRDS("autojags_ref_alliter.Rds") out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(17,18,21)], ref[-c(17,18,21)]) +expect_equal(out[-c(17,18,21)], ref[-c(17,18,21)]) # Parallel---------------------------------------------------------- at_home <- identical( Sys.getenv("AT_HOME"), "TRUE" ) @@ -88,7 +88,7 @@ if(at_home){ ref <- readRDS("autojags_ref.Rds") out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins - expect_identical(out[-c(17,18,20:22)], ref[-c(17,18,20:22)]) + expect_equal(out[-c(17,18,20:22)], ref[-c(17,18,20:22)]) # Save all iter set.seed(123) @@ -103,7 +103,7 @@ if(at_home){ expect_equal(coda::niter(out$samples), 30) ref <- readRDS("autojags_ref_alliter.Rds") - expect_identical(out[-c(17,18,20:22)], ref[-c(17,18,20:22)]) + expect_equal(out[-c(17,18,20:22)], ref[-c(17,18,20:22)]) } # test.Rhat-------------------------------------------------------------------- diff --git a/inst/tinytest/test_jags.R b/inst/tinytest/test_jags.R index be64ffb..6d57a6a 100644 --- a/inst/tinytest/test_jags.R +++ b/inst/tinytest/test_jags.R @@ -32,7 +32,7 @@ ref <- readRDS("longley_reference_fit.Rds") # Remove time/date based elements out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(17,18,21)], ref[-c(17,18,21)]) +expect_equal(out[-c(17,18,21)], ref[-c(17,18,21)]) # Plots pdf(NULL) @@ -56,7 +56,7 @@ dev.off() expect_equal(pp, 0) # Other methods -expect_identical(out$summary, summary(out)) +expect_equal(out$summary, summary(out)) # Double check stats calculations expect_equal(out$mean$alpha, mean(as.matrix(out$samples[,"alpha"]))) @@ -75,7 +75,7 @@ out <- jags(data = data, inits = inits, parameters.to.save = params, ref <- readRDS("reference_codaOnly.Rds") out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(17,18,21)], ref[-c(17,18,21)]) +expect_equal(out[-c(17,18,21)], ref[-c(17,18,21)]) # DIC = FALSE------------------------------------------------------------------ out <- jags(data = data, inits = inits, parameters.to.save = params, @@ -85,7 +85,7 @@ expect_false(out$calc.DIC) ref <- readRDS("reference_noDIC.Rds") out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(15,16,19)], ref[-c(15,16,19)]) +expect_equal(out[-c(15,16,19)], ref[-c(15,16,19)]) # Reordered parameter names---------------------------------------------------- pars_new <- c("mu", "sigma", "alpha", "beta") @@ -95,7 +95,7 @@ out <- jags(data = data, inits = inits, parameters.to.save = pars_new, ref <- readRDS("reference_parsorder.Rds") out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(17,18,21)], ref[-c(17,18,21)]) +expect_equal(out[-c(17,18,21)], ref[-c(17,18,21)]) # Reordered parameter names and no DIC----------------------------------------- pars_new <- c("mu", "sigma", "alpha", "beta") @@ -105,7 +105,7 @@ out <- jags(data = data, inits = inits, parameters.to.save = pars_new, ref <- readRDS("reference_parsorder_noDIC.Rds") out$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out[-c(15,16,19)], ref[-c(15,16,19)]) +expect_equal(out[-c(15,16,19)], ref[-c(15,16,19)]) # Run in parallel-------------------------------------------------------------- at_home <- identical( Sys.getenv("AT_HOME"), "TRUE" ) @@ -116,7 +116,7 @@ if(parallel::detectCores() > 1 & at_home){ model.file = modfile, n.chains = 3, n.adapt = 100, n.iter = 1000, n.burnin = 500, n.thin = 2, verbose=FALSE, parallel=TRUE) ref <- readRDS("longley_reference_fit.Rds") - expect_identical(out[-c(17,18,20:22)], ref[-c(17,18,20:22)]) + expect_equal(out[-c(17,18,20:22)], ref[-c(17,18,20:22)]) # With n.adapt = NULL out <- jags(data = data, inits = inits, parameters.to.save = params, @@ -171,8 +171,8 @@ out <- jags(data = data, inits = inits, parameters.to.save = c("alpha","beta"), model.file = modfile, n.chains = 3, n.adapt = 100, n.iter = 100, n.burnin = 50, n.thin = 1, verbose=FALSE, store.data=TRUE) -expect_identical(out$data, data) -expect_identical(out$inits, run_inits) +expect_equal(out$data, data) +expect_equal(out$inits, run_inits) # Check recovery after process_output errors----------------------------------- # Setting DIC to -999 forces process_output to error for testing diff --git a/inst/tinytest/test_jagsbasic.R b/inst/tinytest/test_jagsbasic.R index b4b33a6..d1c2f95 100644 --- a/inst/tinytest/test_jagsbasic.R +++ b/inst/tinytest/test_jagsbasic.R @@ -27,7 +27,7 @@ out <- jags.basic(data = data, inits = inits, parameters.to.save = params, ref <- readRDS("jagsbasic_reference_fit.Rds") -expect_identical(out, ref) +expect_equal(out, ref) # Saved model and reordered parameter names------------------------------------ set.seed(123) @@ -37,15 +37,15 @@ out <- jags.basic(data = data, inits = inits, parameters.to.save = params, n.burnin = 50, n.thin = 2, verbose=FALSE, save.model=TRUE) ref <- readRDS("jagsbasic_ref_saved.Rds") -expect_identical(names(out), names(ref)) +expect_equal(names(out), names(ref)) out$model <- ref$model -expect_identical(out, ref) +expect_equal(out, ref) # Update----------------------------------------------------------------------- out2 <- update(out, n.iter=100, n.thin = 2, verbose=FALSE) expect_equal(nrow(out2$samples[[1]]), 50) ref <- readRDS('jagsbasic_ref_update.Rds') -expect_identical(names(out2), names(ref)) +expect_equal(names(out2), names(ref)) out2$model <- ref$model expect_equal(out2, ref) @@ -65,13 +65,13 @@ if(parallel::detectCores() > 1 & at_home){ ref <- readRDS("jagsbasic_ref_saved.Rds") out$n.cores <- NULL - expect_identical(names(out), names(ref)) + expect_equal(names(out), names(ref)) out$model <- ref$model - expect_identical(out, ref) + expect_equal(out, ref) out2 <- update(out, n.iter=100, n.thin = 2, verbose=FALSE) ref <- readRDS('jagsbasic_ref_update.Rds') - expect_identical(names(out2), names(ref)) + expect_equal(names(out2), names(ref)) out2$model <- ref$model expect_equal(out2, ref) } diff --git a/inst/tinytest/test_update.R b/inst/tinytest/test_update.R index 42202be..cb3613b 100644 --- a/inst/tinytest/test_update.R +++ b/inst/tinytest/test_update.R @@ -33,14 +33,14 @@ expect_equal(nrow(out2$samples[[1]]), 50) # Remove time/date based elements out2$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out2[-c(17,19,21)], ref[-c(17,19,21)]) +expect_equal(out2[-c(17,19,21)], ref[-c(17,19,21)]) # codaOnly--------------------------------------------------------------------- out2 <- update(out, n.iter=100, n.thin=2, verbose=FALSE, codaOnly='mu') ref <- readRDS("update_ref_codaonly.Rds") out2$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out2[-c(17,19,21)], ref[-c(17,19,21)]) +expect_equal(out2[-c(17,19,21)], ref[-c(17,19,21)]) # Different saved parameters--------------------------------------------------- out2 <- update(out, n.iter=100, n.thin=2, verbose=FALSE, @@ -48,7 +48,7 @@ out2 <- update(out, n.iter=100, n.thin=2, verbose=FALSE, ref <- readRDS("update_ref_diffsaved.Rds") out2$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out2[-c(17,19,21)], ref[-c(17,19,21)]) +expect_equal(out2[-c(17,19,21)], ref[-c(17,19,21)]) # DIC = FALSE------------------------------------------------------------------ out2 <- update(out, n.iter=100, n.thin=2, verbose=FALSE, @@ -58,7 +58,7 @@ ref <- readRDS("update_ref_noDIC.Rds") expect_false(out2$calc.DIC) out2$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins -expect_identical(out2[-c(15,17,19)], ref[-c(15,17,19)]) +expect_equal(out2[-c(15,17,19)], ref[-c(15,17,19)]) # Check recovery after process_output errors----------------------------------- # Setting DIC to -999 forces process_output to error for testing @@ -83,5 +83,5 @@ if(parallel::detectCores() > 1 & at_home){ ref$mcmc.info$sufficient.adapt <- out2$mcmc.info$sufficient.adapt ref$mcmc.info$n.adapt <- out2$mcmc.info$n.adapt out2$mcmc.info$elapsed.mins <- ref$mcmc.inf$elapsed.mins - expect_identical(out2[-c(17,19,21)], ref[-c(17,19,21)]) + expect_equal(out2[-c(17,19,21)], ref[-c(17,19,21)]) } -- cgit v1.2.3