From 6f680e864772a069de122af2452cb2f0b5ef3934 Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 08:23:49 -0700 Subject: [PATCH] Skip tests if suggested packages aren't installed --- tests/testthat/test-dev.R | 1 + tests/testthat/test-log-lik.R | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-dev.R b/tests/testthat/test-dev.R index 062c4d71..8ba1cae1 100644 --- a/tests/testthat/test-dev.R +++ b/tests/testthat/test-dev.R @@ -242,6 +242,7 @@ test_that("gamma_pois log_lik", { }) test_that("gamma_pois deviance", { + skip_if_not_installed("MASS") samples <- ran_gamma_pois(10000, 3, 0.5) mod <- MASS::glm.nb(samples ~ 1) deviance <- sum(dev_gamma_pois(samples, exp(coef(mod)[1]), theta = 1 / mod$theta)) diff --git a/tests/testthat/test-log-lik.R b/tests/testthat/test-log-lik.R index 824bc6f6..2edd956d 100644 --- a/tests/testthat/test-log-lik.R +++ b/tests/testthat/test-log-lik.R @@ -178,21 +178,31 @@ test_that("beta_binom vectorized", { }) test_that("beta_binom log_lik", { + skip_if_not_installed("aods3") samples2 <- ran_beta_binom(100, size = 50, prob = 0.1, theta = 1) data <- data.frame( samples2 = samples2, mod_prob2 = 50 - samples2 ) - mod2 <- aods3::aodml(cbind(samples2, mod_prob2) ~ 1, + mod2 <- aods3::aodml( + cbind(samples2, mod_prob2) ~ 1, data = data, - family = "bb", method = "Nelder-Mead" + family = "bb", + method = "Nelder-Mead" ) est_prob <- ilogit(mod2$b) est_theta <- 2 / (1 / mod2$phi - 1) - expect_equal(mod2$logL, sum(log_lik_beta_binom(samples2, - size = 50, - prob = est_prob, theta = est_theta - ))) + expect_equal( + mod2$logL, + sum( + log_lik_beta_binom( + samples2, + size = 50, + prob = est_prob, + theta = est_theta + ) + ) + ) }) test_that("skewnorm missing values", {