Skip to content

Commit

Permalink
Merge pull request #70 from poissonconsulting/b-conditional-suggests
Browse files Browse the repository at this point in the history
Skip tests if suggested packages aren't installed, remove dependency on aods3 package.
  • Loading branch information
nehill197 authored Aug 20, 2024
2 parents 5d62691 + 8fd0386 commit 50d540a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Imports:
lifecycle,
stats
Suggests:
aods3,
covr,
hms,
ggplot2,
Expand Down
10 changes: 10 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ New maintainer:
Nicole Hill <[email protected]>
Old maintainer(s):
Joe Thorley <[email protected]>

## 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 ──────────────────────────
<packageNotFoundError/error/condition>
Error in `loadNamespace(x)`: there is no package called 'aods3'

## revdepcheck results

Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/_snaps/log-lik.md
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions tests/testthat/test-dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 10 additions & 13 deletions tests/testthat/test-log-lik.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,18 @@ test_that("beta_binom vectorized", {
})

test_that("beta_binom log_lik", {
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"
expect_snapshot(
log_lik_beta_binom(
x = samples,
size = 50,
prob = 0.2,
theta = 1.1
)
)
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
)))
})

test_that("skewnorm missing values", {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-numericise.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 50d540a

Please sign in to comment.