From 6f680e864772a069de122af2452cb2f0b5ef3934 Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 08:23:49 -0700 Subject: [PATCH 1/8] 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", { From 9ec66823db4576211cff532b889fc5d50e16da05 Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 08:34:50 -0700 Subject: [PATCH 2/8] Non-change commit --- tests/testthat/test-log-lik.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-log-lik.R b/tests/testthat/test-log-lik.R index 2edd956d..2b0f0074 100644 --- a/tests/testthat/test-log-lik.R +++ b/tests/testthat/test-log-lik.R @@ -179,6 +179,7 @@ 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, From f5fd13256ef305a29f95424daed584af28d282dc Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 08:34:50 -0700 Subject: [PATCH 3/8] Update cran comments --- cran-comments.md | 9 +++++++++ tests/testthat/test-log-lik.R | 1 + 2 files changed, 10 insertions(+) diff --git a/cran-comments.md b/cran-comments.md index e3e81155..dcc8bc15 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -20,6 +20,15 @@ New maintainer: Nicole Hill Old maintainer(s): Joe Thorley + +## CRAN Issues + +Fixed the following error by conditionally skipping tests that rely on packages listed in suggests, if those packages are not installed. + +══ Failed tests ════════════════════════════════════════════════════════════════ +── Error ('test-log-lik.R:184:3'): beta_binom log_lik ────────────────────────── + +Error in `loadNamespace(x)`: there is no package called 'aods3' ## revdepcheck results diff --git a/tests/testthat/test-log-lik.R b/tests/testthat/test-log-lik.R index 2edd956d..2b0f0074 100644 --- a/tests/testthat/test-log-lik.R +++ b/tests/testthat/test-log-lik.R @@ -179,6 +179,7 @@ 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, From b0f4d56c0498045565a003822f2e96888a3e05b7 Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 10:18:31 -0700 Subject: [PATCH 4/8] Skip test if "hms" package not installed --- tests/testthat/test-numericise.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-numericise.R b/tests/testthat/test-numericise.R index 7f1a482c..88f0ea80 100644 --- a/tests/testthat/test-numericise.R +++ b/tests/testthat/test-numericise.R @@ -92,6 +92,7 @@ test_that("numericise.data.frame", { }) test_that("numericise.hms", { + skip_if_not_installed("hms") x <- structure(10.9, class = c("hms", "difftime"), units = "secs") expect_identical(numericise(x), 10.9) }) From 999f3c318705f43dfbd94302de101bf0fd138c0a Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 10:19:09 -0700 Subject: [PATCH 5/8] Remove non-change commit --- tests/testthat/test-log-lik.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-log-lik.R b/tests/testthat/test-log-lik.R index 2b0f0074..2edd956d 100644 --- a/tests/testthat/test-log-lik.R +++ b/tests/testthat/test-log-lik.R @@ -179,7 +179,6 @@ 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, From 452c4e962330f05f1704960099c21654c6f8ecee Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 17:14:07 -0700 Subject: [PATCH 6/8] Replace test relying on the aods3 package with a snapshot test --- tests/testthat/_snaps/log-lik.md | 21 +++++++++++++++++++++ tests/testthat/test-log-lik.R | 31 +++++++++---------------------- 2 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 tests/testthat/_snaps/log-lik.md diff --git a/tests/testthat/_snaps/log-lik.md b/tests/testthat/_snaps/log-lik.md new file mode 100644 index 00000000..88cd5c62 --- /dev/null +++ b/tests/testthat/_snaps/log-lik.md @@ -0,0 +1,21 @@ +# beta_binom log_lik + + Code + log_lik_beta_binom(x = samples, size = 50, prob = 0.2, theta = 1.1) + Output + [1] -4.976366 -2.395701 -1.375050 -3.917547 -1.375050 -4.314925 -4.409988 + [8] -3.218659 -4.045703 -1.375050 -4.409988 -1.375050 -3.685783 -1.375050 + [15] -1.375050 -2.395701 -1.375050 -1.375050 -4.845012 -1.375050 -2.395701 + [22] -4.631547 -2.787926 -1.375050 -1.375050 -1.375050 -3.983622 -3.769878 + [29] -1.375050 -1.375050 -1.375050 -3.769878 -3.035763 -3.769878 -3.364624 + [36] -3.486792 -5.021646 -1.375050 -2.395701 -1.375050 -1.375050 -1.375050 + [43] -3.218659 -1.375050 -3.592380 -4.045703 -1.375050 -1.375050 -1.375050 + [50] -2.787926 -5.269883 -4.976366 -2.395701 -1.375050 -5.326411 -1.375050 + [57] -1.375050 -4.716959 -1.375050 -3.218659 -1.375050 -3.685783 -5.521217 + [64] -1.375050 -1.375050 -1.375050 -3.486792 -3.364624 -1.375050 -2.395701 + [71] -1.375050 -4.265252 -1.375050 -2.395701 -1.375050 -2.395701 -3.592380 + [78] -3.486792 -1.375050 -3.769878 -2.395701 -4.045703 -1.375050 -3.035763 + [85] -2.395701 -3.218659 -1.375050 -2.787926 -1.375050 -3.035763 -1.375050 + [92] -1.375050 -1.375050 -1.375050 -4.265252 -1.375050 -2.395701 -3.364624 + [99] -3.035763 -1.375050 + diff --git a/tests/testthat/test-log-lik.R b/tests/testthat/test-log-lik.R index 2edd956d..ed4303b5 100644 --- a/tests/testthat/test-log-lik.R +++ b/tests/testthat/test-log-lik.R @@ -178,29 +178,16 @@ 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 + withr::with_seed( + 101, + samples <- ran_beta_binom(100, size = 50, prob = 0.1, theta = 1) ) - mod2 <- aods3::aodml( - cbind(samples2, mod_prob2) ~ 1, - data = data, - 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_snapshot( + log_lik_beta_binom( + x = samples, + size = 50, + prob = 0.2, + theta = 1.1 ) ) }) From 517899c97c033679bb427a8cd41059d38e29ff91 Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 17:14:27 -0700 Subject: [PATCH 7/8] Remove aods3 from suggests --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ee5e566c..f859d0bb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,6 @@ Imports: lifecycle, stats Suggests: - aods3, covr, hms, ggplot2, From 8fd0386680b1655707802b64136fccc4a3d926d3 Mon Sep 17 00:00:00 2001 From: Nicole Hill Date: Mon, 19 Aug 2024 17:14:38 -0700 Subject: [PATCH 8/8] Update cran comments --- cran-comments.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cran-comments.md b/cran-comments.md index dcc8bc15..45279411 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -24,6 +24,7 @@ Old maintainer(s): ## CRAN Issues Fixed the following error by conditionally skipping tests that rely on packages listed in suggests, if those packages are not installed. +After review, also decided to remove the dependency to the 'aods3' package. ══ Failed tests ════════════════════════════════════════════════════════════════ ── Error ('test-log-lik.R:184:3'): beta_binom log_lik ──────────────────────────