From 97fd582e3d652f3918ef5014b910e50b7baf1473 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sat, 20 May 2023 21:15:12 +0200 Subject: [PATCH 01/70] Adapt SR loglik code to new DAISIE equations --- R/DAISIE_SR_loglik_CS.R | 16 +- R/DAISIE_loglik_CS_shift.R | 312 +++++++++++++++++++++++++ tests/testthat/test-DAISIE_SR_loglik.R | 31 ++- 3 files changed, 341 insertions(+), 18 deletions(-) create mode 100644 R/DAISIE_loglik_CS_shift.R diff --git a/R/DAISIE_SR_loglik_CS.R b/R/DAISIE_SR_loglik_CS.R index 2fc4671a..285e1fe0 100644 --- a/R/DAISIE_SR_loglik_CS.R +++ b/R/DAISIE_SR_loglik_CS.R @@ -356,15 +356,17 @@ DAISIE_SR_loglik_CS <- DAISIE_SR_loglik_all <- function( return(check_shift_loglik) } cond = pars2[3] - logp0 = DAISIE_SR_loglik_CS_M1( - pars1 = pars1, + logp0 = DAISIE_loglik_CS_shift( + pars1 = pars1[1:10], pars2 = pars2, brts = datalist[[1]]$island_age, stac = 0, missnumspec = 0, methode = methode, abstolint = abstolint, - reltolint = reltolint + reltolint = reltolint, + verbose = verbose, + tshift = pars1[11] ) if (is.null(datalist[[1]]$not_present)) { not_present <- (datalist[[1]]$not_present_type1 + datalist[[1]]$not_present_type2) @@ -377,15 +379,17 @@ DAISIE_SR_loglik_CS <- DAISIE_SR_loglik_all <- function( loglik <- loglik - logcond if (length(datalist) > 1) { for (i in 2:length(datalist)) { - loglik <- loglik + DAISIE_SR_loglik_CS_M1( - pars1 = pars1, + loglik <- loglik + DAISIE_loglik_CS_shift( + pars1 = pars1[1:10], pars2 = pars2, brts = datalist[[i]]$branching_times, stac = datalist[[i]]$stac, missnumspec = datalist[[i]]$missing_species, methode = methode, abstolint = abstolint, - reltolint = reltolint + reltolint = reltolint, + verbose = verbose, + tshift = pars1[11] ) } } diff --git a/R/DAISIE_loglik_CS_shift.R b/R/DAISIE_loglik_CS_shift.R new file mode 100644 index 00000000..af908b76 --- /dev/null +++ b/R/DAISIE_loglik_CS_shift.R @@ -0,0 +1,312 @@ +DAISIE_loglik_CS_shift <- function(pars1, + pars2, + brts, + stac, + missnumspec, + methode = "lsodes", + abstolint = 1E-16, + reltolint = 1E-10, + verbose, + tshift) { + # stac = status of the clade formed by the immigrant + # . stac == 1 : immigrant is present but has not formed an extant clade + # . stac == 2 : immigrant is not present but has formed an extant clade + # . stac == 3 : immigrant is present and has formed an extant clade + # . stac == 4 : immigrant is present but has not formed an extant clade, + # and it is known when it immigrated. + # . stac == 5 : immigrant is not present and has not formed an extant clade, + # but only an endemic species + # . stac == 6 : like 2, but with max colonization time + # . stac == 7 : like 3, but with max colonization time + # . stac == 8 : like 1, but with min colonization time + # . stac == 9 : like 5, but with min colonization time + # warn if laa becomes Inf + if (any(is.infinite(pars1)) ) { + if (verbose) { + message('One of the parameters is infinite.') + } + } + + if(is.na(pars2[4])) + { + pars2[4] <- 0 + } + ddep <- pars2[2] + K <- pars1[3] + # if (!is.na(pars2[5])) { + # K <- K * pars1[8] + # } + if(length(pars1) == 6) { + probability_of_init_presence <- pars1[6] + pars1 <- pars1[-6] + } else { + probability_of_init_presence <- 0 + } + brts <- -sort(abs(as.numeric(brts)),decreasing = TRUE) + tshift <- -abs(tshift) + if(length(brts) == 1 & sum(brts == 0) == 1) + { + stop('The branching times contain only a 0. This means the island emerged at the present which is not allowed.'); + loglik <- -Inf + return(loglik) + } + if (sum(brts == 0) == 0) { + brts[length(brts) + 1] <- 0 + } + # for stac = 0, brts will contain origin of island and 0; length = 2; + # no. species should be 0 + # for stac = 1, brts will contain origin of island, maximum colonization time + # (usually island age) and 0; length = 3; no. species should be 1 + # for stac = 2, brts will contain origin of island, colonization event, + # branching times, 0; no. species should be no. branching times + 1 + # for stac = 3, brts will contain origin of island, colonization event, + # branching times, 0; no. species should be no. branching times + 2 + # for stac = 4, brts will contain origin of island, colonization event and 0; + # length = 3; no. species should be 1 + # for stac = 5, brts will contain origin of island, maximum colonization time + # (usually island age), and 0; length = 2; number of species should be 1 (+ missing species) + # for stac = 6, brts will contain origin of island, maximum colonization time + # (usually island age), branching times and 0; + # number of species should be no. branching times + 1 + # for stac = 7, brts will contain origin of island, maximum colonization time + # usually island age), branching times and 0; + # number of species should be no. branching times + 2 + # for stac = 8, brts will contain origin of island, maximum colonization time + # usually island age), minimum colonization time and 0; length = 4; + # number of species should be 1 + # for stac = 9, brts will contain origin of island, maximum colonization time + # usually island age), minimum colonization time and 0; length = 4; + # number of species should be 1 + S <- 0 * (stac == 0) + (stac == 1 || stac == 4 || stac == 5 || stac == 8 || stac == 9) + + (length(brts) - 2) * (stac == 2) + (length(brts) - 1) * (stac == 3) + + (length(brts) - 2) * (stac == 6) + (length(brts) - 1) * (stac == 7) + S2 <- S - (stac == 1) - (stac == 3) - (stac == 4) - (stac == 7) + loglik <- -lgamma(S2 + missnumspec + 1) + + lgamma(S2 + 1) + lgamma(missnumspec + 1) + if (min(pars1) < 0) { + message("One or more parameters are negative.") + loglik <- -Inf + return(loglik) + } + if ((ddep == 1 | ddep == 11) & ceiling(K) < (S + missnumspec)) { + if (verbose) { + message('The proposed value of K is incompatible with the number of species + in the clade. Likelihood for this parameter set + will be set to -Inf. \n') + } + loglik <- -Inf + return(loglik) + } + # lac <- pars1[1] + # if(lac == Inf & missnumspec == 0 & length(pars1) == 5) { + # if(verbose) warning('Infinite lambda detected') + # loglik <- DAISIE_loglik_high_lambda(pars1, -brts, stac) + # } else { + if (ddep == 1 | ddep == 11) { + lx <- min( + 1 + max(missnumspec, ceiling(K)), + DDD::roundn(pars2[1]) + missnumspec + ) + } else { + lx <- DDD::roundn(pars2[1]) + missnumspec + } + if(loglik > -Inf) + { + # in all cases we integrate from the origin of the island to the colonization event + # (stac 2, 3, 4), the first branching point (stac = 6, 7), to the maximum colonization + # time (stac = 1, 5, 8, 9) or to the present (stac = 0) + probs <- rep(0,2 * lx + 1) + probs[1] <- 1 - probability_of_init_presence #Q^k_n + probs[lx + 1] <- probability_of_init_presence #Q^{M,k}_n + k1 <- 0 + probs <- DAISIE_integrate_shift(probs,times = brts[1:2],tshift = tshift,loglik_rhs = DAISIE_loglik_rhs,pars1 = pars1,k1 = k1,ddep = ddep,rtol = reltolint,atol = abstolint,method = methode) + cp <- checkprobs2(lv = 2 * lx, loglik, probs, verbose); loglik <- cp[[1]]; probs = cp[[2]] + if(stac == 0) + { + # for stac = 0, the integration was from the origin of the island until + # the present so we can immediately evaluate the probability of no clade + # being present and no immigrant species. + loglik <- loglik + log(probs[1]) + } else + { + if (stac %in% c(1, 5:9) ) + { + # for stac = 1, we now integrate from the maximum colonization time + # (usually the island age + tiny time unit) until the present, where + # we set all probabilities where the immigrant is already present to 0 + # and we evaluate the probability of the immigrant species being + # present, but there can be missing species. + # for stac = 5, we do exactly the same, but we evaluate the + # probability of an endemic species being present alone. + # for stac = 6 and 7, integration is from the maximum colonization + # time until the first branching time. This is the same as we did for + # stac = 1, 5. + # for stac = 8 and 9, integration is from the maximum colonization + # time until the minimum colonization time. + # In all cases we are dealing with a maximum colonization time which + # means that any colonization that took place before this maximum + # colonization time (including presence in the non-oceanic scenario) + # does not count and should be followed by another colonization. + # To allow this we introduce a third set of equations for the + # probability that colonization might have happened before but + # recolonization has not taken place yet (Q_M,n). + epss <- 1.01E-5 #We're taking the risk + if (abs(brts[2] - brts[1]) >= epss) { + probs[(2 * lx + 1):(4 * lx)] <- probs[1:(2 * lx)] + probs[1:(2 * lx)] <- 0 + } else { + probs[(2 * lx + 1):(4 * lx)] <- 0 + } + + probs <- DAISIE_integrate_shift(probs,times = brts[2:3],tshift = tshift,loglik_rhs = DAISIE_loglik_rhs1,pars1 = pars1,k1 = k1,ddep = ddep,rtol = reltolint,atol = abstolint,method = methode) + cp <- checkprobs2(lx, loglik, probs, verbose); loglik <- cp[[1]]; probs <- cp[[2]] + if (stac %in% c(1, 5)) + { + loglik <- loglik + log(probs[(stac == 1) * lx + (stac == 5) + 1 + missnumspec]) + } else if (stac %in% c(6, 7, 8, 9)) + { + probs2 <- rep(0, 3 * lx) + probs2[1:(lx - 1)] <- (1:(lx - 1)) * probs[2:lx] + probs2[(lx + 1):(2 * lx - 1)] <- (1:(lx - 1)) * probs[(lx + 2):(2 * lx)] + probs2[2 * lx + 1] <- probs[(lx + 1)] + probs2[(2 * lx + 2):(3 * lx)] <- 0 + probs <- probs2 + rm(probs2) + if (stac %in% c(8, 9)) + { + k1 <- 1 + probs <- DAISIE_integrate_shift(probs,times = brts[3:4],tshift = tshift,loglik_rhs = DAISIE_loglik_rhs2,pars1 = pars1,k1 = k1,ddep = ddep,rtol = reltolint,atol = abstolint,method = methode) + cp <- checkprobs2(lx, loglik, probs, verbose); loglik <- cp[[1]]; probs = cp[[2]] + loglik <- loglik + log(probs[(stac == 8) * (2 * lx + 1) + (stac == 9) + missnumspec]) + } + } + } else if (stac %in% c(2, 3, 4) ) + { + # for stac = 2, 3, 4, integration is then from the colonization + # event until the first branching time (stac = 2 and 3) or the present + # (stac = 4). We add a set of equations for Q_M,n, the probability + # that the process is compatible with the data, and speciation has not + # happened; during this time immigration is not allowed because it + # would alter the colonization time. + t <- brts[2] + gamvec <- divdepvec( + lac_or_gam = "gam", + pars1 = ifelse(rep(t,5) <= rep(tshift,5), pars1[1:5], pars1[6:10]), + t = t, + lx = lx, + k1 = k1, + ddep = ddep * (ddep == 11 | ddep == 21) + ) + probs[(2 * lx + 1):(3 * lx)] = gamvec[1:lx] * probs[1:lx] + + gamvec[2:(lx + 1)] * probs[(lx + 1):(2 * lx)] + probs[1:(2 * lx)] = 0 + k1 <- 1 + probs <- DAISIE_integrate_shift(probs,times = brts[2:3],tshift = tshift,loglik_rhs = DAISIE_loglik_rhs2,pars1 = pars1,k1 = k1,ddep = ddep,rtol = reltolint,atol = abstolint,method = methode) + cp <- checkprobs2(lx,loglik,probs, verbose); loglik = cp[[1]]; probs = cp[[2]] + if (stac == 4) + # if stac = 4, we're done and we take an element from Q_M,n + { + loglik <- loglik + log(probs[2 * lx + 1 + missnumspec]) + } + } + if (stac %in% c(2, 3, 6, 7) ) + { + # at the first branching point all probabilities of states Q_M,n are + # transferred to probabilities where only endemics are present. Then + # go through the branching points. + S1 <- length(brts) - 1 + startk <- 3 + if(S1 >= startk) + { + t <- brts[startk] + lacvec <- divdepvec( + lac_or_gam = "lac", + pars1 = ifelse(rep(t,5) <= rep(tshift,5), pars1[1:5], pars1[6:10]), + t = t, + lx = lx + stac %in% c(6,7), + k1 = k1, + ddep = ddep + ) + if(stac %in% c(2,3)) + { + probs[1:lx] <- lacvec[1:lx] * (probs[1:lx] + probs[(2 * lx + 1):(3 * lx)]) + probs[(lx + 1):(2 * lx)] <- lacvec[2:(lx + 1)] * probs[(lx + 1):(2 * lx)] + } else { # stac in c(6,7) + probs[1:(lx - 1)] <- lacvec[2:lx] * + ((1:(lx - 1)) * probs[2:lx] + probs[(2 * lx + 1):(3 * lx - 1)]) + probs[(lx + 1):(2 * lx - 1)] <- lacvec[3:(lx + 1)] * (1:(lx - 1)) * + probs[(lx + 2):(2 * lx)] + probs[lx] <- 0 + probs[2 * lx] <- 0 + } + probs <- probs[-c((2 * lx + 2):(3 * lx))] + probs[2 * lx + 1] <- 0 + # After speciation, colonization is allowed again (re-immigration) + # all probabilities of states with the immigrant present are set to + # zero and all probabilities of states with endemics present are + # transported to the state with the colonist present waiting for + # speciation to happen. We also multiply by the (possibly diversity- + # dependent) immigration rate. + for (k in startk:S1) + { + k1 <- k - 1 + probs <- DAISIE_integrate_shift(probs,times = brts[k:(k+1)],tshift = tshift,loglik_rhs = DAISIE_loglik_rhs,pars1 = pars1,k1 = k1,ddep = ddep,rtol = reltolint,atol = abstolint,method = methode) + cp <- checkprobs2(lx, loglik, probs, verbose); loglik <- cp[[1]]; probs = cp[[2]] + if(k < S1) + { + # speciation event + t <- brts[k + 1] + lacvec <- divdepvec( + lac_or_gam = "lac", + pars1 = ifelse(rep(t,5) <= rep(tshift,5), pars1[1:5], pars1[6:10]), + t = t, + lx = lx, + k1 = k1, + ddep = ddep + ) + probs[1:(2 * lx)] <- c(lacvec[1:lx], lacvec[2:(lx + 1)]) * + probs[1:(2 * lx)] + } + } + } + # we evaluate the probability of the phylogeny with any missing species at the present without (stac = 2 or stac = 6) or with (stac = 3 or stac = 7) the immigrant species + loglik <- loglik + log(probs[(stac %in% c(3, 7)) * lx + 1 + missnumspec]) + } + } + } + #} + + if (length(pars1) == 11) { # CHANGE + print_parameters_and_loglik(pars = c(stac, pars1[5:10]), # should this be 6:10, or 6:11? + loglik = loglik, + verbose = pars2[4], + type = 'clade_loglik') + } else { + print_parameters_and_loglik(pars = c(stac, pars1[1:5]), + loglik = loglik, + verbose = pars2[4], + type = 'clade_loglik') + } + if (is.na(loglik)) { + message("NA in loglik encountered. Changing to -Inf.") + loglik <- -Inf + stop('stopping') + } + loglik <- as.numeric(loglik) + #testit::assert(is.numeric(loglik)) + return(loglik) +} + +DAISIE_integrate_shift <- function(probs,times,tshift,loglik_rhs,pars1,k1,ddep,rtol,atol,method) { + if(tshift > times[1] && tshift >= times[2]) { + probs <- DAISIE_integrate(probs,c(times[1:2]),loglik_rhs,c(pars1[1:5],k1,ddep),rtol = rtol,atol = atol,method = method) + } else + if(tshift > times[1] && tshift < times[2]) { + probs <- DAISIE_integrate(probs,c(times[1],tshift),loglik_rhs,c(pars1[1:5],k1,ddep),rtol = rtol,atol = atol,method = method) + probs <- DAISIE_integrate(probs,c(tshift,times[2]),loglik_rhs,c(pars1[6:10],k1,ddep),rtol = rtol,atol = atol,method = method) + } else + if(tshift <= times[1] && tshift < times[2]) { + probs <- DAISIE_integrate(probs,c(times[1:2]),loglik_rhs,c(pars1[6:10],k1,ddep),rtol = rtol,atol = atol,method = method) + } + return(probs) +} diff --git a/tests/testthat/test-DAISIE_SR_loglik.R b/tests/testthat/test-DAISIE_SR_loglik.R index 74807182..28f901d8 100644 --- a/tests/testthat/test-DAISIE_SR_loglik.R +++ b/tests/testthat/test-DAISIE_SR_loglik.R @@ -11,15 +11,20 @@ test_that("The SR loglik code works", { 0.077, 0.956, Inf, - 0.655, + 0.138, 0.442, 0.1951 ) pars2 <- c(100, 11, 0, 0) - loglik <- DAISIE_SR_loglik_CS(pars1 = pars1, - pars2 = pars2, - datalist = Biwa_datalist) - testthat::expect_equal(loglik, -227.7108, tol = 1E-3) + loglik_shift <- DAISIE_SR_loglik_CS(pars1 = pars1, + pars2 = pars2, + datalist = Biwa_datalist, + methode = 'odeint::runge_kutta_fehlberg78') + loglik_no_shift <- DAISIE_loglik_CS(pars1 = pars1[1:5], + pars2 = pars2, + datalist = Biwa_datalist) + testthat::expect_equal(loglik_shift, loglik_no_shift, tol = 1E-3) + testthat::expect_equal(loglik_no_shift, -245.6298, tol = 1E-3) Macaronesia_datalist <- NULL rm(Macaronesia_datalist) @@ -40,13 +45,13 @@ test_that("The SR loglik code works", { pars1mat <- matrix(pars1, nrow = 8, ncol = 11, byrow = T) expected_loglik <- c( -Inf, - -257.7311, + -252.7293, -Inf, - -252.5254, + -246.9084, -Inf, - -280.0562, + -272.9101, -Inf, - -252.6193 + -247.1446 ) # No shift in cladogenesis rate older before # colonization of diversifying lineages @@ -61,12 +66,14 @@ test_that("The SR loglik code works", { # No shift in anagenetic rate older than any known non-endemic pars1mat[7, 5] <- 0.01; pars1mat[7, 10] <- 0.1; pars1mat[8, 5] <- 0.01; pars1mat[8, 10] <- 0.1; pars1mat[8, 11] <- 2.9 + loglik <- rep(0,8) for (i in 1:8) { - loglik <- DAISIE_SR_loglik_CS( + loglik[i] <- DAISIE_SR_loglik_CS( pars1 = pars1mat[i, -12], pars2 = pars2, - datalist = Macaronesia_datalist[[2]] + datalist = Macaronesia_datalist[[2]], + methode = 'odeint::runge_kutta_fehlberg78' ) - testthat::expect_equal(loglik, expected_loglik[i], tol = 1E-3) } + testthat::expect_equal(loglik, expected_loglik, tol = 1E-3) }) From e761cf28e1af472d9876c2c7b549eaa76459f95d Mon Sep 17 00:00:00 2001 From: rsetienne Date: Fri, 2 Jun 2023 12:16:31 +0200 Subject: [PATCH 02/70] Fix bug in setting trparsfix and idparsfix if pop_type2_present is not available --- R/DAISIE_ML1.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index d3b3ca20..8d44333e 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -25,7 +25,7 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, } else { trpars1 <- rep(0, 6) prop_type2_present <- which(idparsfix == 11) - if(!is.null(prop_type2_present)) { + if(length(prop_type2_present) > 0) { trparsfix <- trparsfix[-prop_type2_present] idparsfix <- idparsfix[-prop_type2_present] } From 98b42f8da0555bc5a457faae7b4e6e9ecce7bcf7 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Fri, 2 Jun 2023 12:16:52 +0200 Subject: [PATCH 03/70] Fix printing bug --- R/DAISIE_loglik_CS.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/DAISIE_loglik_CS.R b/R/DAISIE_loglik_CS.R index d3677680..1bbb2993 100644 --- a/R/DAISIE_loglik_CS.R +++ b/R/DAISIE_loglik_CS.R @@ -1034,9 +1034,11 @@ DAISIE_loglik_CS <- DAISIE_loglik_all <- function( reltolint = reltolint) } } + print_parameters_and_loglik(pars = pars, loglik = loglik, verbose = pars2[4], + parnames = c("lambda^c", "mu", "K", "gamma", "lambda^a", "prob_init_pres"), type = 'island_loglik') return(loglik) } From 3caf43a16897c30bf9c65d2448ddc899566ac9de Mon Sep 17 00:00:00 2001 From: rsetienne Date: Fri, 2 Jun 2023 12:17:28 +0200 Subject: [PATCH 04/70] Make test case easier to adjust --- tests/testthat/test-DAISIE_ML1.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-DAISIE_ML1.R b/tests/testthat/test-DAISIE_ML1.R index 58c56872..c12a1a6d 100644 --- a/tests/testthat/test-DAISIE_ML1.R +++ b/tests/testthat/test-DAISIE_ML1.R @@ -7,9 +7,9 @@ test_that("use", { datalist <- Galapagos_datalist initparsopt <- c(2.5, 2.7, 20, 0.009, 1.01) ddmodel <- 11 - idparsopt <- 1:5 - parsfix <- NULL - idparsfix <- NULL + idparsopt <- c(1,2,3,4,5) + parsfix <- c() + idparsfix <- c() tested_MLE <- DAISIE_ML1( datalist = datalist, initparsopt = initparsopt, From 0cad23b72fe0a954771255408665659e4ef4cea6 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Fri, 2 Jun 2023 17:55:06 +0200 Subject: [PATCH 05/70] Documentation create_CS_version --- R/create_pars.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/create_pars.R b/R/create_pars.R index 56a022bb..cbf3d91a 100644 --- a/R/create_pars.R +++ b/R/create_pars.R @@ -187,14 +187,14 @@ create_trait_pars_2K <- function(trans_rate, #' \code{"immigration"}, or \code{"anagenesis"} #' @param par_sd standard deviation of the parameter to relax #' @param par_upper_bound upper bound of the parameter to relax -#' @return A list of two elements +#' @return A list of four elements #' \itemize{ #' \item{model: the CS model to run, options are \code{1} for single rate #' DAISIE model, \code{2} for multi-rate DAISIE, or \code{0} for IW test #' model} -#' \item{relaxed_par: the parameter to relax (integrate over). Options are -#' \code{"cladogenesis"}, \code{"extinction"}, \code{"carrying_capacity"}, -#' \code{"immigration"}, or \code{"anagenesis"}} +#' \item{relaxed_par: the parameter to relax (integrate over). +#' \item{par_sd: the standard deviation of the parameter to relax} +#' \item{par_upperbound: upper bound of the parameter to relax.} #' } #' @export create_CS_version <- function(model = 1, From 907d885930870c6282e017f521c4bab7855ebb25 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Mon, 5 Jun 2023 09:52:52 +0200 Subject: [PATCH 06/70] Use par_upper_bound also in finding optimum [run ci] --- R/DAISIE_loglik_integrate.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/DAISIE_loglik_integrate.R b/R/DAISIE_loglik_integrate.R index d8eb6baf..e45a500c 100644 --- a/R/DAISIE_loglik_integrate.R +++ b/R/DAISIE_loglik_integrate.R @@ -30,7 +30,7 @@ DAISIE_loglik_integrate <- function( integrated_loglik <- integral_peak( logfun = Vectorize(DAISIE_loglik_integrand, vectorize.args = "DAISIE_par"), - xx = sort(c(seq(-20, 20, 2), + xx = sort(c(seq(-20, min(20,log(par_upper_bound)), 2), seq(log(par_mean) - 1, log(par_mean) + 1), log((par_mean + 10 * par_sd) / par_mean))), pars1 = pars1, @@ -189,7 +189,6 @@ integral_peak <- function(logfun, par_mean, par_sd)) } - # determine integrand peak yy <- xx + logfun(exp(xx), pars1, @@ -262,7 +261,7 @@ integral_peak <- function(logfun, } Q1 <- stats::integrate(f = fun, lower = lower, - upper = exp(xmax), + upper = min(par_upper_bound,exp(xmax)), subdivisions = 1000, rel.tol = 1e-10, abs.tol = 1e-10)$value From a553e800aefd88a813004a993cdd214ca96d390a Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 6 Jun 2023 18:19:00 +0200 Subject: [PATCH 07/70] Add assert [run ci] --- R/DAISIE_ML1.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index 8d44333e..34eabdf4 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -24,8 +24,9 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, trpars1 <- rep(0, 11) } else { trpars1 <- rep(0, 6) + testit::assert(!is.null(prop_type2_present)) prop_type2_present <- which(idparsfix == 11) - if(length(prop_type2_present) > 0) { + if (length(prop_type2_present) > 0) { trparsfix <- trparsfix[-prop_type2_present] idparsfix <- idparsfix[-prop_type2_present] } From 330214bfba670ee2cd15e4b9f2fcab42693ccaf7 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 6 Jun 2023 19:04:05 +0200 Subject: [PATCH 08/70] Last check assert [run ci] --- R/DAISIE_ML1.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index 34eabdf4..25f8d7b3 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -24,8 +24,8 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, trpars1 <- rep(0, 11) } else { trpars1 <- rep(0, 6) - testit::assert(!is.null(prop_type2_present)) prop_type2_present <- which(idparsfix == 11) + testit::assert(!is.null(prop_type2_present)) if (length(prop_type2_present) > 0) { trparsfix <- trparsfix[-prop_type2_present] idparsfix <- idparsfix[-prop_type2_present] From 9bae3092723a3ebb6d379b302e56a33c343a14a4 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 6 Jun 2023 19:04:25 +0200 Subject: [PATCH 09/70] Remove assert --- R/DAISIE_ML1.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index 25f8d7b3..2fb1edb9 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -25,7 +25,6 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, } else { trpars1 <- rep(0, 6) prop_type2_present <- which(idparsfix == 11) - testit::assert(!is.null(prop_type2_present)) if (length(prop_type2_present) > 0) { trparsfix <- trparsfix[-prop_type2_present] idparsfix <- idparsfix[-prop_type2_present] From f5d7c676930ac9321c92e418dd23f00e3362fde2 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 6 Jun 2023 19:04:30 +0200 Subject: [PATCH 10/70] Fix doc --- R/create_pars.R | 2 +- man/create_CS_version.Rd | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/create_pars.R b/R/create_pars.R index cbf3d91a..691e8027 100644 --- a/R/create_pars.R +++ b/R/create_pars.R @@ -192,7 +192,7 @@ create_trait_pars_2K <- function(trans_rate, #' \item{model: the CS model to run, options are \code{1} for single rate #' DAISIE model, \code{2} for multi-rate DAISIE, or \code{0} for IW test #' model} -#' \item{relaxed_par: the parameter to relax (integrate over). +#' \item{relaxed_par: the parameter to relax (integrate over).} #' \item{par_sd: the standard deviation of the parameter to relax} #' \item{par_upperbound: upper bound of the parameter to relax.} #' } diff --git a/man/create_CS_version.Rd b/man/create_CS_version.Rd index 0409316d..6144a84f 100644 --- a/man/create_CS_version.Rd +++ b/man/create_CS_version.Rd @@ -25,14 +25,14 @@ model} \item{par_upper_bound}{upper bound of the parameter to relax} } \value{ -A list of two elements +A list of four elements \itemize{ \item{model: the CS model to run, options are \code{1} for single rate DAISIE model, \code{2} for multi-rate DAISIE, or \code{0} for IW test model} - \item{relaxed_par: the parameter to relax (integrate over). Options are -\code{"cladogenesis"}, \code{"extinction"}, \code{"carrying_capacity"}, -\code{"immigration"}, or \code{"anagenesis"}} + \item{relaxed_par: the parameter to relax (integrate over).} + \item{par_sd: the standard deviation of the parameter to relax} + \item{par_upperbound: upper bound of the parameter to relax.} } } \description{ From 3c8b8c90765eafc38408614372d1043aaa525bdd Mon Sep 17 00:00:00 2001 From: rsetienne Date: Fri, 9 Jun 2023 16:29:39 +0200 Subject: [PATCH 11/70] space --- tests/testthat/test-integration_DAISIE.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 70eac94b..b89abb34 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -88,7 +88,6 @@ test_that("IW and CS loglik is same when K = Inf", { methode = "odeint::runge_kutta_fehlberg78" ) - loglik_CS <- DAISIE_loglik_CS( pars1 = pars1, pars2 = pars2, From 94a99a3d3a457455f858be3ec431f4b1e70a5166 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Mon, 12 Jun 2023 15:55:11 +0200 Subject: [PATCH 12/70] Add first test [run ci] --- tests/testthat/test-integration_DAISIE.R | 140 ++++++++++++++++++----- 1 file changed, 113 insertions(+), 27 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index b89abb34..cd37269e 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -190,35 +190,35 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial prese test_that("DAISIE_ML simple case works with estimating probability of initial presence", { - skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), - message = "Run only on CI") - skip_on_cran() + skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), + message = "Run only on CI") + skip_on_cran() - expected_mle <- data.frame( - lambda_c = 2.54079308283855, - mu = 2.66563367593515, - K = 6249.71023359369, - gamma = 0.00919247416324124, - lambda_a = 1.01076206116211, - prob_init_pres = 9.45796543536632e-06, - loglik = -75.9935681347126, - df = 6L, - conv = 0L - ) + expected_mle <- data.frame( + lambda_c = 2.54079308283855, + mu = 2.66563367593515, + K = 6249.71023359369, + gamma = 0.00919247416324124, + lambda_a = 1.01076206116211, + prob_init_pres = 9.45796543536632e-06, + loglik = -75.9935681347126, + df = 6L, + conv = 0L + ) - utils::data(Galapagos_datalist) - invisible(capture.output( - tested_mle <- DAISIE_ML( - datalist = Galapagos_datalist, - initparsopt = c(2.5, 2.7, 20, 0.009, 1.01, 0.001), - ddmodel = 11, - idparsopt = 1:6, - parsfix = NULL, - idparsfix = NULL - ) - )) - expect_equal(tested_mle, expected_mle) -}) + utils::data(Galapagos_datalist) + invisible(capture.output( + tested_mle <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01, 0.001), + ddmodel = 11, + idparsopt = 1:6, + parsfix = NULL, + idparsfix = NULL + ) + )) + expect_equal(tested_mle, expected_mle) + }) test_that("The parameter choice for 2type DAISIE_ML works", { Galapagos_datalist_2types <- NULL @@ -384,3 +384,89 @@ test_that("conditioning works", { ) expect_equal(loglik_CS_2type_cond5, -61.3735194058527) }) + +# Test for fixed parameters ML results should be different from all free parameters +test_that("ML with fixed parameters should be different from free parameters", { + skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), + message = "Run only on CI") + skip_on_cran() + expected_mle <- data.frame( + lambda_c = 2.583731356303842, + mu = 2.708828027514834, + K = 2992.207701921788, + gamma = 0.00937711049761019, + lambda_a = 0.9993246958280274, + loglik = -75.99266304738612, + df = 5L, + conv = 0L + ) + utils::data(Galapagos_datalist) + + tested_mle_free <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = NULL, + idparsfix = NULL, + verbose = 0 + ) + tested_mle_fix_clado <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 2:5, + parsfix = 2.5, + idparsfix = 1, + verbose = 0 + ) + tested_mle_fix_mu <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = c(1, 3:5), + parsfix = 2.7, + idparsfix = 2, + verbose = 0 + ) + tested_mle_fix_k <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 0.009, 1.01), + ddmodel = 11, + idparsopt = c(1, 2, 4, 5), + parsfix = 20, + idparsfix = 3, + verbose = 0 + ) + tested_mle_fix_immig <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 1.01), + ddmodel = 11, + idparsopt = c(1:3, 5), + parsfix = 0.009, + idparsfix = 4, + verbose = 0 + ) + tested_mle_fix_ana <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009), + ddmodel = 11, + idparsopt = 1:4, + parsfix = 1.01, + idparsfix = 5, + verbose = 0 + ) + + # Fixing one parameter should not return the same as a leaving all free + expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_clado))) + expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_mu))) + expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_k))) + expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_immig))) + expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_ana))) +}) + +# Test for fixed parameter should not return that parameter as 0 unless set to 0 + +# Nonoceanic case loglik should be different if 6th parameter is non-zero + + From 874f14b91fe8e69b24ff9e44db1e33b389e5da45 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Mon, 12 Jun 2023 16:08:11 +0200 Subject: [PATCH 13/70] Second set of tests [run ci] --- tests/testthat/test-integration_DAISIE.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index cd37269e..0191412a 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -385,8 +385,8 @@ test_that("conditioning works", { expect_equal(loglik_CS_2type_cond5, -61.3735194058527) }) -# Test for fixed parameters ML results should be different from all free parameters -test_that("ML with fixed parameters should be different from free parameters", { +test_that("ML with fixed parameters should be different from free parameters + and be nonzero", { skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), message = "Run only on CI") skip_on_cran() @@ -463,9 +463,16 @@ test_that("ML with fixed parameters should be different from free parameters", { expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_k))) expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_immig))) expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_ana))) -}) -# Test for fixed parameter should not return that parameter as 0 unless set to 0 + + # Fixing one parameter should not return pars as 0, unless set to it + expect_false(0 %in% tested_mle_fix_clado[1:5]) + expect_false(0 %in% tested_mle_fix_mu[1:5]) + expect_false(0 %in% tested_mle_fix_k[1:5]) + expect_false(0 %in% tested_mle_fix_immig[1:5]) + expect_false(0 %in% tested_mle_fix_ana[1:5]) + +}) # Nonoceanic case loglik should be different if 6th parameter is non-zero From 9c394e7a943632bcf81129825b17e0ef8fb94c78 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 13 Jun 2023 16:25:51 +0200 Subject: [PATCH 14/70] Nonoceanic test WIP --- tests/testthat/test-integration_DAISIE.R | 67 +++++++++++++++++------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 0191412a..22f09cd3 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -146,17 +146,27 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence ) utils::data(Galapagos_datalist) - invisible(capture.output( tested_mle <- DAISIE_ML( datalist = Galapagos_datalist, initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, parsfix = 0, - idparsfix = 6 + idparsfix = 6, + verbose = 0 ) - )) + expected_calculated_mle <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = NULL, + idparsfix = NULL, + verbose = 0 + ) + expect_equal(expected_mle, tested_mle) + expect_equal(expected_calculated_mle, tested_mle) }) test_that("DAISIE_ML simple case works with nonzero probability of initial presence", { @@ -175,18 +185,44 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial prese ) utils::data(Galapagos_datalist) - invisible(capture.output( - tested_mle <- DAISIE_ML( - datalist = Galapagos_datalist, - initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), - ddmodel = 11, - idparsopt = 1:5, - parsfix = 0.1, - idparsfix = 6 - ) - )) + tested_mle <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = 0.1, + idparsfix = 6, + verbose = 0 + ) expect_equal(expected_mle, tested_mle) }) + # HERE +# Nonoceanic case loglik should be different if 6th parameter is non-zero +test_that("DAISIE_ML simple case works with nonzero probability of initial presence", { + skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), + message = "Run only on CI") + utils::data(Galapagos_datalist) + + tested_mle_zero <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = 0, + idparsfix = 6, + verbose = 0 + ) + tested_mle_nonzero <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = 0.1, + idparsfix = 6, + verbose = 0 + ) + expect_false(isTRUE(all.equal(expected_mle, tested_mle))) +}) test_that("DAISIE_ML simple case works with estimating probability of initial presence", { @@ -471,9 +507,4 @@ test_that("ML with fixed parameters should be different from free parameters expect_false(0 %in% tested_mle_fix_k[1:5]) expect_false(0 %in% tested_mle_fix_immig[1:5]) expect_false(0 %in% tested_mle_fix_ana[1:5]) - }) - -# Nonoceanic case loglik should be different if 6th parameter is non-zero - - From c9617300c7ff6b833514121f7629d58ea074f078 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 13 Jun 2023 17:13:32 +0200 Subject: [PATCH 15/70] Finish nonoceanic and zero probability of initial presence test --- tests/testthat/test-integration_DAISIE.R | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 22f09cd3..dc8de047 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -166,10 +166,13 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence ) expect_equal(expected_mle, tested_mle) - expect_equal(expected_calculated_mle, tested_mle) + # Results match if prob_init_pres is removed + expect_equal(expected_calculated_mle, tested_mle[-6]) + }) -test_that("DAISIE_ML simple case works with nonzero probability of initial presence", { +test_that("DAISIE_ML simple case works with nonzero probability of initial + presence", { skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), message = "Run only on CI") expected_mle <- data.frame( @@ -196,9 +199,11 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial prese ) expect_equal(expected_mle, tested_mle) }) - # HERE -# Nonoceanic case loglik should be different if 6th parameter is non-zero -test_that("DAISIE_ML simple case works with nonzero probability of initial presence", { + + +test_that("DAISIE_ML with nonzero probability of initial presence gives + different results from DAISIE_ML with 0 probability of initial + presence", { skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), message = "Run only on CI") utils::data(Galapagos_datalist) @@ -221,7 +226,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial prese idparsfix = 6, verbose = 0 ) - expect_false(isTRUE(all.equal(expected_mle, tested_mle))) + expect_false(isTRUE(all.equal(tested_mle_zero, tested_mle_nonzero))) }) test_that("DAISIE_ML simple case works with estimating probability of initial From b3184ed3ec4c61fe99e1e99bec0a76d4f132c34d Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 13 Jun 2023 17:46:01 +0200 Subject: [PATCH 16/70] Update nonzero probability of intial presence test refence values [run ci] --- tests/testthat/test-integration_DAISIE.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index dc8de047..803f78d9 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -176,13 +176,13 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), message = "Run only on CI") expected_mle <- data.frame( - lambda_c = 2.58373135630384, - mu = 2.70882802751483, - K = 2992.20770192179, - gamma = 0.00937711049761019, - lambda_a = 0.999324695828027, + lambda_c = 3.30567366427796, + mu = 3.86584745010284, + K = Inf, + gamma = 0.0144177568387567, + lambda_a = 0.699608034134341, prob_init_pres = 0.1, - loglik = -75.9926628720867, + loglik = -78.9245109502749, df = 5L, conv = 0L ) From 8a2c2d2624bddc48c1f3d0f7b56049fe653788cd Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 13 Jun 2023 18:00:38 +0200 Subject: [PATCH 17/70] Lower tol for speed [run ci] --- tests/testthat/test-integration_DAISIE.R | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 803f78d9..64313d50 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -431,16 +431,6 @@ test_that("ML with fixed parameters should be different from free parameters skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), message = "Run only on CI") skip_on_cran() - expected_mle <- data.frame( - lambda_c = 2.583731356303842, - mu = 2.708828027514834, - K = 2992.207701921788, - gamma = 0.00937711049761019, - lambda_a = 0.9993246958280274, - loglik = -75.99266304738612, - df = 5L, - conv = 0L - ) utils::data(Galapagos_datalist) tested_mle_free <- DAISIE_ML( @@ -450,6 +440,7 @@ test_that("ML with fixed parameters should be different from free parameters idparsopt = 1:5, parsfix = NULL, idparsfix = NULL, + tol = c(1e-2, 1e-3, 1e-4), verbose = 0 ) tested_mle_fix_clado <- DAISIE_ML( @@ -459,6 +450,7 @@ test_that("ML with fixed parameters should be different from free parameters idparsopt = 2:5, parsfix = 2.5, idparsfix = 1, + tol = c(1e-2, 1e-3, 1e-4), verbose = 0 ) tested_mle_fix_mu <- DAISIE_ML( @@ -468,6 +460,7 @@ test_that("ML with fixed parameters should be different from free parameters idparsopt = c(1, 3:5), parsfix = 2.7, idparsfix = 2, + tol = c(1e-2, 1e-3, 1e-4), verbose = 0 ) tested_mle_fix_k <- DAISIE_ML( @@ -477,6 +470,7 @@ test_that("ML with fixed parameters should be different from free parameters idparsopt = c(1, 2, 4, 5), parsfix = 20, idparsfix = 3, + tol = c(1e-2, 1e-3, 1e-4), verbose = 0 ) tested_mle_fix_immig <- DAISIE_ML( @@ -486,6 +480,7 @@ test_that("ML with fixed parameters should be different from free parameters idparsopt = c(1:3, 5), parsfix = 0.009, idparsfix = 4, + tol = c(1e-2, 1e-3, 1e-4), verbose = 0 ) tested_mle_fix_ana <- DAISIE_ML( @@ -495,6 +490,7 @@ test_that("ML with fixed parameters should be different from free parameters idparsopt = 1:4, parsfix = 1.01, idparsfix = 5, + tol = c(1e-2, 1e-3, 1e-4), verbose = 0 ) From 55b560c323854698c1d40005c4f6ff7a4ba26a99 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Wed, 28 Jun 2023 17:17:25 +0200 Subject: [PATCH 18/70] Some verbosity in test [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 64313d50..9b81c754 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -195,7 +195,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 0 + verbose = 1 ) expect_equal(expected_mle, tested_mle) }) From cc4a63f582b557e10d7de55dd2b8916b006f92a5 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 29 Jun 2023 17:15:14 +0200 Subject: [PATCH 19/70] Even more prints [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 9b81c754..0362f736 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -195,7 +195,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 1 + verbose = 3 ) expect_equal(expected_mle, tested_mle) }) From 394b3c2a5b71a8f7da65cbd88d6088c020d48b5e Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 25 Jul 2023 10:35:43 +0200 Subject: [PATCH 20/70] Better diag --- R/DAISIE_ML1.R | 2 ++ R/DAISIE_ML_CS.R | 2 +- man/DAISIE_ML.Rd | 2 +- tests/testthat/test-integration_DAISIE.R | 16 +++++++++++++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index 2fb1edb9..1808d888 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -25,8 +25,10 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, } else { trpars1 <- rep(0, 6) prop_type2_present <- which(idparsfix == 11) + message(length(prop_type2_present) > 0) if (length(prop_type2_present) > 0) { trparsfix <- trparsfix[-prop_type2_present] + message(proptype2_present) idparsfix <- idparsfix[-prop_type2_present] } } diff --git a/R/DAISIE_ML_CS.R b/R/DAISIE_ML_CS.R index 933896f5..18b40c7c 100644 --- a/R/DAISIE_ML_CS.R +++ b/R/DAISIE_ML_CS.R @@ -49,7 +49,7 @@ #' \code{\link{DAISIE_sim_cr_shift}} #' @references Valente, L.M., A.B. Phillimore and R.S. Etienne (2015). #' Equilibrium and non-equilibrium dynamics simultaneously operate in the -#' Galapagos islands. Ecology Letters 18: 844-852. . +#' Galapagos islands. Ecology Letters 18: 844-852. . #' @keywords models #' @examples #' diff --git a/man/DAISIE_ML.Rd b/man/DAISIE_ML.Rd index 098d672d..3cf746dd 100644 --- a/man/DAISIE_ML.Rd +++ b/man/DAISIE_ML.Rd @@ -353,7 +353,7 @@ DAISIE_ML( \references{ Valente, L.M., A.B. Phillimore and R.S. Etienne (2015). Equilibrium and non-equilibrium dynamics simultaneously operate in the -Galapagos islands. Ecology Letters 18: 844-852. . +Galapagos islands. Ecology Letters 18: 844-852. . } \seealso{ \code{\link{DAISIE_loglik_all}}, diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 0362f736..d243ee1e 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -188,15 +188,25 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial ) utils::data(Galapagos_datalist) - tested_mle <- DAISIE_ML( + ## capture all the output to a file. + zz <- file("all.Rout", open = "wt") + sink(zz) + sink(zz, type = "message") + + try(tested_mle <- DAISIE_ML( datalist = Galapagos_datalist, initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 3 - ) + verbose = 3, + methode = "odeint::bulirsch_stoer" + )) + + ## revert output back to the console -- only then access the file! + sink(type = "message") + sink() expect_equal(expected_mle, tested_mle) }) From 73c7b06a0e33a854bfeeb8ce3cdb169ec890d817 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Wed, 26 Jul 2023 01:01:34 +0200 Subject: [PATCH 21/70] Default --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index d243ee1e..f56ee2ba 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -200,8 +200,8 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 3, - methode = "odeint::bulirsch_stoer" + verbose = 3 + # methode = "odeint::bulirsch_stoer" )) ## revert output back to the console -- only then access the file! From 272a9ea08a9c20825cecce213292ed39b8b9f0ca Mon Sep 17 00:00:00 2001 From: Neves-P Date: Wed, 26 Jul 2023 01:02:41 +0200 Subject: [PATCH 22/70] Comment out output stream [run ci] --- tests/testthat/test-integration_DAISIE.R | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index f56ee2ba..937c6431 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -189,24 +189,26 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial utils::data(Galapagos_datalist) ## capture all the output to a file. - zz <- file("all.Rout", open = "wt") - sink(zz) - sink(zz, type = "message") + # zz <- file("all.Rout", open = "wt") + # sink(zz) + # sink(zz, type = "message") - try(tested_mle <- DAISIE_ML( + # try( + tested_mle <- DAISIE_ML( datalist = Galapagos_datalist, initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 3 - # methode = "odeint::bulirsch_stoer" - )) + verbose = 3, + methode = "odeint::bulirsch_stoer" + ) +# ) ## revert output back to the console -- only then access the file! - sink(type = "message") - sink() + # sink(type = "message") + # sink() expect_equal(expected_mle, tested_mle) }) From 345c77bcfce691b732827e653ddaafa1179ecd0e Mon Sep 17 00:00:00 2001 From: Neves-P Date: Wed, 26 Jul 2023 01:03:51 +0200 Subject: [PATCH 23/70] Silence for debugging [run ci] --- tests/testthat/test-integration_DAISIE.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 937c6431..4f8c110e 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -201,7 +201,8 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 3, + verbose = 0, + # verbose = 3, methode = "odeint::bulirsch_stoer" ) # ) From 8f0e12dc4d26391d26d4dbc5165eeaa1a7ee52b1 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 15:04:23 +0200 Subject: [PATCH 24/70] Try very low parsfix [run ci] --- tests/testthat/test-integration_DAISIE.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 4f8c110e..1a030f14 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.1, + prob_init_pres = 0.0001, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -194,7 +194,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial # sink(zz, type = "message") # try( - tested_mle <- DAISIE_ML( + tested_mle <- suppressMessages(DAISIE_ML( datalist = Galapagos_datalist, initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, @@ -203,8 +203,8 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsfix = 6, verbose = 0, # verbose = 3, - methode = "odeint::bulirsch_stoer" - ) + # methode = "odeint::bulirsch_stoer" + )) # ) ## revert output back to the console -- only then access the file! From ca553254bdde8c147c1d0326ceb2c3fda4530db9 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 15:05:01 +0200 Subject: [PATCH 25/70] Correctly try with low value [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 1a030f14..e307b25e 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -199,7 +199,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.1, + parsfix = 0.0001, idparsfix = 6, verbose = 0, # verbose = 3, From bd85f43389ed978bea79dcd28a70d38cd60822c5 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 15:05:22 +0200 Subject: [PATCH 26/70] Try high value [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index e307b25e..5216de4f 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.0001, + prob_init_pres = 0.5, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -199,7 +199,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.0001, + parsfix = 0.5, idparsfix = 6, verbose = 0, # verbose = 3, From a14fbc485072edd3854824d0093b7f7264b81b4c Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 15:06:15 +0200 Subject: [PATCH 27/70] Actually run the low value [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 5216de4f..e307b25e 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.5, + prob_init_pres = 0.0001, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -199,7 +199,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.5, + parsfix = 0.0001, idparsfix = 6, verbose = 0, # verbose = 3, From f6d3c0d06b9481cd3bb09a6c24a44d96e0ef3631 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 15:54:32 +0200 Subject: [PATCH 28/70] Typo --- R/DAISIE_ML1.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index 1808d888..a7ee2126 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -28,7 +28,7 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, message(length(prop_type2_present) > 0) if (length(prop_type2_present) > 0) { trparsfix <- trparsfix[-prop_type2_present] - message(proptype2_present) + message(prop_type2_present) idparsfix <- idparsfix[-prop_type2_present] } } @@ -49,6 +49,7 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, pars1[idparsnoshift] <- pars1[idparsnoshift - 5] } } + testit::assert(non_oceanic_option) if (min(pars1) < 0 | (pars1[6] > 1 && non_oceanic_option == TRUE)) { loglik <- -Inf } else { From b9fc34f2fd990f2b55ee6d58de9eb6eb99879a86 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:04:19 +0200 Subject: [PATCH 29/70] Typo [run ci] Low value --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index e307b25e..af777004 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -201,7 +201,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsopt = 1:5, parsfix = 0.0001, idparsfix = 6, - verbose = 0, + verbose = 0 # verbose = 3, # methode = "odeint::bulirsch_stoer" )) From 7ddf38ae1baf436fe26a631d8745d616d25b3048 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:04:44 +0200 Subject: [PATCH 30/70] Again high value [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index af777004..007e7d5a 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.0001, + prob_init_pres = 0.5, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -199,7 +199,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.0001, + parsfix = 0.5, idparsfix = 6, verbose = 0 # verbose = 3, From 8f05353689fed771be8180f39ce1ca88ca6c6e3f Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:05:09 +0200 Subject: [PATCH 31/70] Back to first value [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 007e7d5a..09d2b38a 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.5, + prob_init_pres = 0.1, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -199,7 +199,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.5, + parsfix = 0.1, idparsfix = 6, verbose = 0 # verbose = 3, From 47d8f2f6287162bb973a3266f2a21a9c1a15c89e Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:21:26 +0200 Subject: [PATCH 32/70] Delete debug statements --- R/DAISIE_ML1.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index a7ee2126..2fb1edb9 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -25,10 +25,8 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, } else { trpars1 <- rep(0, 6) prop_type2_present <- which(idparsfix == 11) - message(length(prop_type2_present) > 0) if (length(prop_type2_present) > 0) { trparsfix <- trparsfix[-prop_type2_present] - message(prop_type2_present) idparsfix <- idparsfix[-prop_type2_present] } } @@ -49,7 +47,6 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, pars1[idparsnoshift] <- pars1[idparsnoshift - 5] } } - testit::assert(non_oceanic_option) if (min(pars1) < 0 | (pars1[6] > 1 && non_oceanic_option == TRUE)) { loglik <- -Inf } else { From 804fe78256a686a44febfa4077280a937bd84acb Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:21:35 +0200 Subject: [PATCH 33/70] Try initial test again [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 09d2b38a..1710909e 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -194,7 +194,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial # sink(zz, type = "message") # try( - tested_mle <- suppressMessages(DAISIE_ML( + tested_mle <- DAISIE_ML( datalist = Galapagos_datalist, initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, @@ -204,7 +204,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial verbose = 0 # verbose = 3, # methode = "odeint::bulirsch_stoer" - )) + ) # ) ## revert output back to the console -- only then access the file! From a9e7f6d166f00a59b63f5ce8a57b03e741a52a45 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:49:01 +0200 Subject: [PATCH 34/70] And again high value [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 1710909e..40e5457e 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.1, + prob_init_pres = 0.5, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -199,7 +199,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.1, + parsfix = 0.5, idparsfix = 6, verbose = 0 # verbose = 3, From e69e7d85a40577e87dd1347f6f63eb64bdc5d877 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:49:37 +0200 Subject: [PATCH 35/70] And again low value [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 40e5457e..93e371e5 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.5, + prob_init_pres = 0.0001, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -199,7 +199,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.5, + parsfix = 0.0001, idparsfix = 6, verbose = 0 # verbose = 3, From b06b00f1873021d30f9f08b1f690bacdfa79cc7b Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 27 Jul 2023 16:51:48 +0200 Subject: [PATCH 36/70] Initial value with R code [run ci] --- tests/testthat/test-integration_DAISIE.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 93e371e5..d4e5b47c 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.0001, + prob_init_pres = 0.1, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -199,11 +199,11 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, idparsopt = 1:5, - parsfix = 0.0001, + parsfix = 0.1, idparsfix = 6, - verbose = 0 + verbose = 0, # verbose = 3, - # methode = "odeint::bulirsch_stoer" + methode = "deSolve_R::lsodes" ) # ) From a79d273fdcd9b8acf51b42f4aed6f7c8a068d01c Mon Sep 17 00:00:00 2001 From: Neves-P Date: Wed, 30 Aug 2023 16:42:04 +0200 Subject: [PATCH 37/70] BACKUP --- tests/testthat/test-integration_DAISIE.R | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index d4e5b47c..0021cb8c 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -181,7 +181,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial K = Inf, gamma = 0.0144177568387567, lambda_a = 0.699608034134341, - prob_init_pres = 0.1, + prob_init_pres = 0.0001, loglik = -78.9245109502749, df = 5L, conv = 0L @@ -192,9 +192,29 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial # zz <- file("all.Rout", open = "wt") # sink(zz) # sink(zz, type = "message") - +options(digits = 15) # try( - tested_mle <- DAISIE_ML( + tested_mle_low <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = 0.0001, + idparsfix = 6, + verbose = 0 + # verbose = 3, + ) + tested_mle_high <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = 0.5, + idparsfix = 6, + verbose = 0 + # verbose = 3, + ) + tested_mle_mid <- DAISIE_ML( datalist = Galapagos_datalist, initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), ddmodel = 11, @@ -202,10 +222,10 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial parsfix = 0.1, idparsfix = 6, verbose = 0, + methode = deSolve_R::lsodes # verbose = 3, - methode = "deSolve_R::lsodes" ) -# ) + # ) ## revert output back to the console -- only then access the file! # sink(type = "message") From fecafd07bda947cc3635135debea03107d86b5b7 Mon Sep 17 00:00:00 2001 From: joshwlambert Date: Mon, 2 Oct 2023 21:22:40 +0100 Subject: [PATCH 38/70] error in DAISIE_loglik_integrate when relaxed param is infinite --- R/DAISIE_loglik_integrate.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/DAISIE_loglik_integrate.R b/R/DAISIE_loglik_integrate.R index d8eb6baf..7675c4b3 100644 --- a/R/DAISIE_loglik_integrate.R +++ b/R/DAISIE_loglik_integrate.R @@ -27,6 +27,11 @@ DAISIE_loglik_integrate <- function( "immigration", "anagenesis") == CS_version$relaxed_par) par_mean <- pars1[pick] + + if (is.infinite(par_mean) || is.infinite(par_sd)) { + stop("The relaxed parameter mean or standard deviation is infinite") + } + integrated_loglik <- integral_peak( logfun = Vectorize(DAISIE_loglik_integrand, vectorize.args = "DAISIE_par"), From eec280ba160effd536636fb01d29f03e14dc3d14 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Thu, 5 Oct 2023 13:11:04 +0200 Subject: [PATCH 39/70] Date change --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fdbe3656..4168e64d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction -Version: 4.4.0 -Date: 2023-03-29 +Version: 4.4.1 +Date: 2023-10-05 Depends: R (>= 4.2.0) biocViews: Imports: From a197a522a7dd7bb8731be58ff50143259a3efb7a Mon Sep 17 00:00:00 2001 From: rsetienne Date: Thu, 5 Oct 2023 13:13:33 +0200 Subject: [PATCH 40/70] Date change [run_ci] --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4168e64d..fdbe3656 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction -Version: 4.4.1 -Date: 2023-10-05 +Version: 4.4.0 +Date: 2023-03-29 Depends: R (>= 4.2.0) biocViews: Imports: From a809da0e1f7e7ab72b9cd764e7acac906182debb Mon Sep 17 00:00:00 2001 From: rsetienne Date: Thu, 5 Oct 2023 13:14:55 +0200 Subject: [PATCH 41/70] Date change [run ci] --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fdbe3656..4168e64d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction -Version: 4.4.0 -Date: 2023-03-29 +Version: 4.4.1 +Date: 2023-10-05 Depends: R (>= 4.2.0) biocViews: Imports: From cbad0ec42801d0b6e03ff1b627de681e29f6a776 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 17:37:06 +0200 Subject: [PATCH 42/70] Typo --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 0021cb8c..b438719a 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -222,7 +222,7 @@ options(digits = 15) parsfix = 0.1, idparsfix = 6, verbose = 0, - methode = deSolve_R::lsodes + methode = "deSolve_R::lsodes" # verbose = 3, ) # ) From 0a962110dd1e9eca7df8dfbba37cd0e0fbef977c Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 17:39:15 +0200 Subject: [PATCH 43/70] Update date again [run ci] --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4168e64d..5e76e686 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction Version: 4.4.1 -Date: 2023-10-05 +Date: 2023-10-07 Depends: R (>= 4.2.0) biocViews: Imports: From 683c2d1c2ea75da394a71e2ff75421571440c226 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 18:38:53 +0200 Subject: [PATCH 44/70] Try first test implementation [run ci] --- tests/testthat/test-integration_DAISIE.R | 94 ++++++++++-------------- 1 file changed, 37 insertions(+), 57 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index b438719a..8f83178d 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -173,65 +173,45 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence test_that("DAISIE_ML simple case works with nonzero probability of initial presence", { - skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), - message = "Run only on CI") - expected_mle <- data.frame( - lambda_c = 3.30567366427796, - mu = 3.86584745010284, - K = Inf, - gamma = 0.0144177568387567, - lambda_a = 0.699608034134341, - prob_init_pres = 0.0001, - loglik = -78.9245109502749, - df = 5L, - conv = 0L - ) - utils::data(Galapagos_datalist) + skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), + message = "Run only on CI") + expected_mle <- data.frame( + lambda_c = 3.30567366427796, + mu = 3.86584745010284, + K = Inf, + gamma = 0.0144177568387567, + lambda_a = 0.699608034134341, + prob_init_pres = 0.1, + loglik = -78.9245109502749, + df = 5L, + conv = 0L + ) + utils::data(Galapagos_datalist) - ## capture all the output to a file. - # zz <- file("all.Rout", open = "wt") - # sink(zz) - # sink(zz, type = "message") -options(digits = 15) - # try( - tested_mle_low <- DAISIE_ML( - datalist = Galapagos_datalist, - initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), - ddmodel = 11, - idparsopt = 1:5, - parsfix = 0.0001, - idparsfix = 6, - verbose = 0 - # verbose = 3, - ) - tested_mle_high <- DAISIE_ML( - datalist = Galapagos_datalist, - initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), - ddmodel = 11, - idparsopt = 1:5, - parsfix = 0.5, - idparsfix = 6, - verbose = 0 - # verbose = 3, - ) - tested_mle_mid <- DAISIE_ML( - datalist = Galapagos_datalist, - initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), - ddmodel = 11, - idparsopt = 1:5, - parsfix = 0.1, - idparsfix = 6, - verbose = 0, - methode = "deSolve_R::lsodes" - # verbose = 3, - ) - # ) + ## capture all the output to a file. + # zz <- file("all.Rout", open = "wt") + # sink(zz) + # sink(zz, type = "message") + + # try( + tested_mle <- DAISIE_ML( + datalist = Galapagos_datalist, + initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), + ddmodel = 11, + idparsopt = 1:5, + parsfix = 0.1, + idparsfix = 6, + verbose = 0 + # verbose = 3, + # methode = "odeint::bulirsch_stoer" + ) + # ) - ## revert output back to the console -- only then access the file! - # sink(type = "message") - # sink() - expect_equal(expected_mle, tested_mle) -}) + ## revert output back to the console -- only then access the file! + # sink(type = "message") + # sink() + expect_equal(expected_mle, tested_mle) + }) test_that("DAISIE_ML with nonzero probability of initial presence gives From 3a9e909f30a7fee33143060ecdd6af9a1b019072 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 20:47:02 +0200 Subject: [PATCH 45/70] Another integrator [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 8f83178d..8e1d7d9d 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -201,9 +201,9 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 0 + verbose = 0, # verbose = 3, - # methode = "odeint::bulirsch_stoer" + methode = "odeint::bulirsch_stoer" ) # ) From 7092c183da7ecdd0a43125a30bc173aa16ba187d Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 20:47:40 +0200 Subject: [PATCH 46/70] rk dopri5 [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 8e1d7d9d..2a98483c 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -203,7 +203,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsfix = 6, verbose = 0, # verbose = 3, - methode = "odeint::bulirsch_stoer" + methode = "odeint::runge_kutta_dopri5" ) # ) From d4f7cbc8f807507bbbaf5f36a27efba3c0b4aab6 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 20:48:10 +0200 Subject: [PATCH 47/70] odeint::runge_kutta_cash_karp54 [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 2a98483c..3d097751 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -203,7 +203,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsfix = 6, verbose = 0, # verbose = 3, - methode = "odeint::runge_kutta_dopri5" + methode = "odeint::runge_kutta_cash_karp54" ) # ) From 94a4c9daed1a5c8bc69b280f4c2d500b2c869626 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 20:48:32 +0200 Subject: [PATCH 48/70] odeint::runge_kutta_fehlberg78 [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 3d097751..ef311e7d 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -203,7 +203,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsfix = 6, verbose = 0, # verbose = 3, - methode = "odeint::runge_kutta_cash_karp54" + methode = "odeint::runge_kutta_fehlberg78" ) # ) From dfc99b7223e800dedcc4f80affb22e8075b0a2ad Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 20:51:13 +0200 Subject: [PATCH 49/70] lsodes fortran [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index ef311e7d..fdf513ca 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -203,7 +203,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsfix = 6, verbose = 0, # verbose = 3, - methode = "odeint::runge_kutta_fehlberg78" + methode = "lsodes" ) # ) From 98114526f528ea1a387d48aa0507433a695b798e Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sat, 7 Oct 2023 20:52:05 +0200 Subject: [PATCH 50/70] lsodes R [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index fdf513ca..6fcd82f9 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -203,7 +203,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsfix = 6, verbose = 0, # verbose = 3, - methode = "lsodes" + methode = "deSolve_R::lsodes" ) # ) From d70e59d52b3021033061b78665724cba6dbed037 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 10:08:12 +0200 Subject: [PATCH 51/70] Fixing documentation issues --- R/DAISIE_loglik_integrate.R | 2 +- R/DAISIE_utils.R | 2 -- R/default_params_doc.R | 12 +++++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/DAISIE_loglik_integrate.R b/R/DAISIE_loglik_integrate.R index e45a500c..e8bc3092 100644 --- a/R/DAISIE_loglik_integrate.R +++ b/R/DAISIE_loglik_integrate.R @@ -152,11 +152,11 @@ cum_rho <- function(par_upper_bound, DAISIE_dist_pars) { #' sets the width of the interval to find the maximum in #' @param ymaxthreshold sets the deviation allowed in finding the maximum #' among the xx -#' @param ... any arguments of the function to optimize #' @return the result of the integration #' @references Haegeman, B. & R.S. Etienne (2017). A general sampling formula #' for community structure data. Methods in Ecology & Evolution. In press. #' @keywords internal +#' integral_peak <- function(logfun, xx = seq(-20, 20, 2), xcutoff = 2, diff --git a/R/DAISIE_utils.R b/R/DAISIE_utils.R index 35bc8d67..da83b360 100644 --- a/R/DAISIE_utils.R +++ b/R/DAISIE_utils.R @@ -225,8 +225,6 @@ order_pars1 <- function(pars1) #' #' @param pars A vector of 5 elements with the model parameters #' @param relaxed_par A string determining which parameter is relaxed -#' @param relaxed_rate_pars A list of two numbers, element one is the -#' distribution mean, element two is the distribution standard deviation (sd) #' #' @return A vector of parameters. #' @keywords internal diff --git a/R/default_params_doc.R b/R/default_params_doc.R index 1cc094b0..82584110 100644 --- a/R/default_params_doc.R +++ b/R/default_params_doc.R @@ -434,10 +434,10 @@ #' } #' @param relaxed_par A string determining which parameter is relaxed in a #' relaxed rate model. -#' @param relaxed_rate_pars A two element list the first element is the mean -#' of the gamma distribution, the second element is the standard deviation of -#' the gamma distribution. List can be created with -#' \code{create_relaxed_rate_pars()} +#' @param relaxed_rate_pars A list of two numbers, element one is the +#' distribution mean, element two is the distribution standard deviation (sd). +#' Currently the distribution is the gamma distribution. The list can be created +#' with \code{create_relaxed_rate_pars()}. #' @param brts Numeric vector of branching times #' @param stac Numeric of Endemicity status #' @param missnumspec Numeric of missing species @@ -606,7 +606,9 @@ default_params_doc <- function( ext_rate, carr_cap, immig_rate, - ana_rate + ana_rate, + islands, + sort_clade_sizes ) { # Nothing } From 94056af8ae438f36905a32f4c754f1fece791ba9 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 10:27:42 +0200 Subject: [PATCH 52/70] Add testthat:: --- tests/testthat/test-integration_DAISIE.R | 52 ++++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 6fcd82f9..6f79b0a1 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -37,7 +37,7 @@ test_that("loglik macaronesia 2 type works", { Macaronesia_datalist[[i]], methode = "lsodes") } - expect_equal(loglik, -449.921430187808) + testthat::expect_equal(loglik, -449.921430187808) }) test_that("clade specific rate-shift loglik works", { @@ -57,7 +57,7 @@ test_that("clade specific rate-shift loglik works", { datalist = Galapagos_datalist, methode = "ode45", CS_version = 1) - expect_equal(SR_loglik_CS, loglik_CS) + testthat::expect_equal(SR_loglik_CS, loglik_CS) }) test_that("IW and CS loglik is same when K = Inf", { @@ -96,8 +96,8 @@ test_that("IW and CS loglik is same when K = Inf", { CS_version = 1 ) - expect_equal(loglik_IW, loglik_IW2, tol = 5E-6) - expect_equal(loglik_IW, loglik_CS, tol = 5E-6) + testthat::expect_equal(loglik_IW, loglik_IW2, tol = 5E-6) + testthat::expect_equal(loglik_IW, loglik_CS, tol = 5E-6) }) test_that("DAISIE_ML simple case works", { @@ -126,7 +126,7 @@ test_that("DAISIE_ML simple case works", { idparsfix = NULL ) )) - expect_equal(expected_mle, tested_mle) + testthat::expect_equal(expected_mle, tested_mle) }) test_that("DAISIE_ML simple case works with zero probability of initial presence", { @@ -165,9 +165,9 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence verbose = 0 ) - expect_equal(expected_mle, tested_mle) + testthat::expect_equal(expected_mle, tested_mle) # Results match if prob_init_pres is removed - expect_equal(expected_calculated_mle, tested_mle[-6]) + testthat::expect_equal(expected_calculated_mle, tested_mle[-6]) }) @@ -210,7 +210,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial ## revert output back to the console -- only then access the file! # sink(type = "message") # sink() - expect_equal(expected_mle, tested_mle) + testthat::expect_equal(expected_mle, tested_mle) }) @@ -239,7 +239,7 @@ test_that("DAISIE_ML with nonzero probability of initial presence gives idparsfix = 6, verbose = 0 ) - expect_false(isTRUE(all.equal(tested_mle_zero, tested_mle_nonzero))) + testthat::expect_false(isTRUE(all.equal(tested_mle_zero, tested_mle_nonzero))) }) test_that("DAISIE_ML simple case works with estimating probability of initial @@ -271,7 +271,7 @@ test_that("DAISIE_ML simple case works with estimating probability of initial idparsfix = NULL ) )) - expect_equal(tested_mle, expected_mle) + testthat::expect_equal(tested_mle, expected_mle) }) test_that("The parameter choice for 2type DAISIE_ML works", { @@ -294,7 +294,7 @@ test_that("The parameter choice for 2type DAISIE_ML works", { maxiter = 30 ) )) - expect_equal(fit$loglik, -74.7557, tol = 1E-3) + testthat::expect_equal(fit$loglik, -74.7557, tol = 1E-3) }) test_that("conditioning works", { @@ -362,7 +362,7 @@ test_that("conditioning works", { pars2_2type_cond0, Galapagos_datalist_2types ) - expect_equal(loglik_CS_2type_cond0, -61.7028188767349) + testthat::expect_equal(loglik_CS_2type_cond0, -61.7028188767349) # Cond 1 ## 1 type @@ -376,7 +376,7 @@ test_that("conditioning works", { methode = 'ode45', CS_version = 1 ) - expect_equal(loglik_CS_1type_cond1, -96.45757823017264) + testthat::expect_equal(loglik_CS_1type_cond1, -96.45757823017264) ## 2 type data(Galapagos_datalist_2types, package = "DAISIE") @@ -399,7 +399,7 @@ test_that("conditioning works", { pars2_2type_cond1, Galapagos_datalist_2types ) - expect_equal(loglik_CS_2type_cond1, -61.4375954386635) + testthat::expect_equal(loglik_CS_2type_cond1, -61.4375954386635) # Cond 5 ## 1 type @@ -413,7 +413,7 @@ test_that("conditioning works", { methode = 'ode45', CS_version = 1 ) - expect_equal(loglik_CS_1type_cond5, -95.14000237210625) + testthat::expect_equal(loglik_CS_1type_cond5, -95.14000237210625) ## 2 type data(Galapagos_datalist_2types, package = "DAISIE") @@ -436,7 +436,7 @@ test_that("conditioning works", { pars2_2type_cond5, Galapagos_datalist_2types ) - expect_equal(loglik_CS_2type_cond5, -61.3735194058527) + testthat::expect_equal(loglik_CS_2type_cond5, -61.3735194058527) }) test_that("ML with fixed parameters should be different from free parameters @@ -508,17 +508,17 @@ test_that("ML with fixed parameters should be different from free parameters ) # Fixing one parameter should not return the same as a leaving all free - expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_clado))) - expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_mu))) - expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_k))) - expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_immig))) - expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_ana))) + testthat::expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_clado))) + testthat::expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_mu))) + testthat::expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_k))) + testthat::expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_immig))) + testthat::expect_false(isTRUE(all.equal(tested_mle_free, tested_mle_fix_ana))) # Fixing one parameter should not return pars as 0, unless set to it - expect_false(0 %in% tested_mle_fix_clado[1:5]) - expect_false(0 %in% tested_mle_fix_mu[1:5]) - expect_false(0 %in% tested_mle_fix_k[1:5]) - expect_false(0 %in% tested_mle_fix_immig[1:5]) - expect_false(0 %in% tested_mle_fix_ana[1:5]) + testthat::expect_false(0 %in% tested_mle_fix_clado[1:5]) + testthat::expect_false(0 %in% tested_mle_fix_mu[1:5]) + testthat::expect_false(0 %in% tested_mle_fix_k[1:5]) + testthat::expect_false(0 %in% tested_mle_fix_immig[1:5]) + testthat::expect_false(0 %in% tested_mle_fix_ana[1:5]) }) From 316bdff9afba90b1807508fb37155f9106ebf2cf Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 10:29:25 +0200 Subject: [PATCH 53/70] Delete space [run ci] --- tests/testthat/test-integration_DAISIE.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 6f79b0a1..324012dd 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -168,7 +168,6 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence testthat::expect_equal(expected_mle, tested_mle) # Results match if prob_init_pres is removed testthat::expect_equal(expected_calculated_mle, tested_mle[-6]) - }) test_that("DAISIE_ML simple case works with nonzero probability of initial From 773c06c23ae6070b0593d0ece546dc264cc414a5 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 12:03:34 +0200 Subject: [PATCH 54/70] Update documentation [run ci] --- R/default_params_doc.R | 2 +- man/DAISIE_count_species.Rd | 2 +- man/default_params_doc.Rd | 14 ++++++++------ man/integral_peak.Rd | 2 -- man/sample_relaxed_rate.Rd | 3 --- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/R/default_params_doc.R b/R/default_params_doc.R index 82584110..2ebaafe5 100644 --- a/R/default_params_doc.R +++ b/R/default_params_doc.R @@ -473,7 +473,7 @@ #' @param islands Island datalist or simulated data in DAISIE datalist format. #' Can be a single island (empirical data) generated with DAISIE_dataprep or #' DAISIEprep. Can also be simulated data generated with DAISIE_sim function. -#' @param sort_clade_sizes Default sort_clade_sizes=T outputs clade sizes +#' @param sort_clade_sizes Default sort_clade_sizes = T outputs clade sizes #' sorted in ascending order of number of species. sort_clade_sizes=F outputs #' clade sizes in the same order as they appear in the input datalist. #' diff --git a/man/DAISIE_count_species.Rd b/man/DAISIE_count_species.Rd index c522d1eb..fc3df015 100644 --- a/man/DAISIE_count_species.Rd +++ b/man/DAISIE_count_species.Rd @@ -11,7 +11,7 @@ DAISIE_count_species(islands, sort_clade_sizes = TRUE) Can be a single island (empirical data) generated with DAISIE_dataprep or DAISIEprep. Can also be simulated data generated with DAISIE_sim function.} -\item{sort_clade_sizes}{Default sort_clade_sizes=T outputs clade sizes +\item{sort_clade_sizes}{Default sort_clade_sizes = T outputs clade sizes sorted in ascending order of number of species. sort_clade_sizes=F outputs clade sizes in the same order as they appear in the input datalist.} } diff --git a/man/default_params_doc.Rd b/man/default_params_doc.Rd index a352fc87..5665810c 100644 --- a/man/default_params_doc.Rd +++ b/man/default_params_doc.Rd @@ -131,7 +131,9 @@ default_params_doc( ext_rate, carr_cap, immig_rate, - ana_rate + ana_rate, + islands, + sort_clade_sizes ) } \arguments{ @@ -690,10 +692,10 @@ Default is 1.} \item{relaxed_par}{A string determining which parameter is relaxed in a relaxed rate model.} -\item{relaxed_rate_pars}{A two element list the first element is the mean -of the gamma distribution, the second element is the standard deviation of -the gamma distribution. List can be created with -\code{create_relaxed_rate_pars()}} +\item{relaxed_rate_pars}{A list of two numbers, element one is the +distribution mean, element two is the distribution standard deviation (sd). +Currently the distribution is the gamma distribution. The list can be created +with \code{create_relaxed_rate_pars()}.} \item{brts}{Numeric vector of branching times} @@ -732,7 +734,7 @@ relaxed-rate model} Can be a single island (empirical data) generated with DAISIE_dataprep or DAISIEprep. Can also be simulated data generated with DAISIE_sim function.} -\item{sort_clade_sizes}{Default sort_clade_sizes=T outputs clade sizes +\item{sort_clade_sizes}{Default sort_clade_sizes = T outputs clade sizes sorted in ascending order of number of species. sort_clade_sizes=F outputs clade sizes in the same order as they appear in the input datalist.} } diff --git a/man/integral_peak.Rd b/man/integral_peak.Rd index 0a837384..0234e6fe 100644 --- a/man/integral_peak.Rd +++ b/man/integral_peak.Rd @@ -35,8 +35,6 @@ sets the width of the interval to find the maximum in} \item{ymaxthreshold}{sets the deviation allowed in finding the maximum among the xx} - -\item{...}{any arguments of the function to optimize} } \value{ the result of the integration diff --git a/man/sample_relaxed_rate.Rd b/man/sample_relaxed_rate.Rd index 75700cbf..5280ab2f 100644 --- a/man/sample_relaxed_rate.Rd +++ b/man/sample_relaxed_rate.Rd @@ -10,9 +10,6 @@ sample_relaxed_rate(pars, relaxed_par) \item{pars}{A vector of 5 elements with the model parameters} \item{relaxed_par}{A string determining which parameter is relaxed} - -\item{relaxed_rate_pars}{A list of two numbers, element one is the -distribution mean, element two is the distribution standard deviation (sd)} } \value{ A vector of parameters. From c2cf697dac53955a7fb72c34ab07f966b85bd3f0 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 12:13:34 +0200 Subject: [PATCH 55/70] Adding testthat:: and tol = 1E-3 to nonoceanic test --- tests/testthat/test-DAISIE_loglik_CS.R | 22 +++++++++++----------- tests/testthat/test-integration_DAISIE.R | 2 +- tests/testthat/test-odeint.R | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/testthat/test-DAISIE_loglik_CS.R b/tests/testthat/test-DAISIE_loglik_CS.R index 034fe078..693e1afc 100644 --- a/tests/testthat/test-DAISIE_loglik_CS.R +++ b/tests/testthat/test-DAISIE_loglik_CS.R @@ -1,4 +1,4 @@ -test_that("DAISIE_loglik_CS_choice produces correct output for CS_version 1", { +test_that("DAISIE_loglik_CS_choice produces correnict output for CS_version 1", { skip_if(Sys.getenv("CI") == "", message = "Run only on CI") skip_on_cran() pars1 <- c(2.000, 2.700, 20.000, 0.009, 1.010) @@ -14,8 +14,8 @@ test_that("DAISIE_loglik_CS_choice produces correct output for CS_version 1", { stac = stac, missnumspec = missnumspec) - expect_true(is.numeric(loglik)) - expect_equal(loglik, -17.6535269346579) + testthat::expect_true(is.numeric(loglik)) + testthat::expect_equal(loglik, -17.6535269346579) }) @@ -41,8 +41,8 @@ test_that("DAISIE_loglik_CS_choice produces correct output for relaxed-rate stac = stac, missnumspec = missnumspec, CS_version = CS_version))) - expect_true(is.numeric(loglik)) - expect_equal(loglik, -9.550184206825) + testthat::expect_true(is.numeric(loglik)) + testthat::expect_equal(loglik, -9.550184206825) }) @@ -74,7 +74,7 @@ test_that("DAISIE_loglik_CS_choice produces same output for CS_version = 0 missnumspec = missnumspec, CS_version = CS_version) - expect_equal(loglik0, loglik1) + testthat::expect_equal(loglik0, loglik1) }) test_that("DAISIE_loglik_all produces correct output for relaxed-rate model", { @@ -95,8 +95,8 @@ test_that("DAISIE_loglik_all produces correct output for relaxed-rate model", { reltolint = 1e-10 ) ))) - expect_true(is.numeric(loglik)) - expect_equal(loglik, -77.50300644907) + testthat::expect_true(is.numeric(loglik)) + testthat::expect_equal(loglik, -77.50300644907) }) test_that("DAISIE_loglik produces correct output", { @@ -160,7 +160,7 @@ test_that("DAISIE_loglik_all produces same output for CS_version 0 and 1 with CS_version = 1, abstolint = 1e-16, reltolint = 1e-10) - expect_equal(loglik_CS01, loglik_CS11, tol = 5E-6) + testthat::expect_equal(loglik_CS01, loglik_CS11, tol = 5E-6) }) test_that("DAISIE_loglik_CS_choice produces equivalent output for ODEINT RKCK54 @@ -189,7 +189,7 @@ test_that("DAISIE_loglik_CS_choice produces equivalent output for ODEINT RKCK54 missnumspec = missnumspec, methode = "odeint::runge_kutta_cash_karp54" ) - expect_equal(expected = loglik1, object = loglik2) + testthat::expect_equal(expected = loglik1, object = loglik2) }) test_that("DAISIE_loglik_CS_choice produces equivalent @@ -226,6 +226,6 @@ test_that("DAISIE_loglik_CS_choice produces equivalent methode = "odeint::runge_kutta_fehlberg78" ) ) - expect_equal(expected = loglik1, object = loglik2) + testthat::expect_equal(expected = loglik1, object = loglik2) }) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 324012dd..aac33888 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -165,7 +165,7 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence verbose = 0 ) - testthat::expect_equal(expected_mle, tested_mle) + testthat::expect_equal(expected_mle, tested_mle, tol = 1E-3) # Results match if prob_init_pres is removed testthat::expect_equal(expected_calculated_mle, tested_mle[-6]) }) diff --git a/tests/testthat/test-odeint.R b/tests/testthat/test-odeint.R index eb03992a..8fae2a5d 100644 --- a/tests/testthat/test-odeint.R +++ b/tests/testthat/test-odeint.R @@ -22,9 +22,9 @@ test_that("odeint solvers give the same result as deSolve solvers", { loglik_lsodes <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) methode <- 'lsoda' loglik_lsoda <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) - expect_equal(loglik_lsoda_R,loglik_lsoda) - expect_equal(loglik_lsodes_R,loglik_lsodes) - expect_equal(loglik_lsoda,loglik_lsodes) + testthat::expect_equal(loglik_lsoda_R,loglik_lsoda) + testthat::expect_equal(loglik_lsodes_R,loglik_lsodes) + testthat::expect_equal(loglik_lsoda,loglik_lsodes) methode <- 'odeint::runge_kutta_cash_karp54' loglik_rkck54 <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) methode <- 'odeint::runge_kutta_fehlberg78' @@ -33,10 +33,10 @@ test_that("odeint solvers give the same result as deSolve solvers", { loglik_rkd5 <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) methode <- 'odeint::bulirsch_stoer' loglik_bs <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) - expect_equal(loglik_lsodes, loglik_rkck54) - expect_equal(loglik_lsodes, loglik_rkf78) - expect_equal(loglik_lsodes, loglik_rkd5) - expect_equal(loglik_lsodes, loglik_bs) + testthat:: expect_equal(loglik_lsodes, loglik_rkck54) + testthat::expect_equal(loglik_lsodes, loglik_rkf78) + testthat::expect_equal(loglik_lsodes, loglik_rkd5) + testthat::expect_equal(loglik_lsodes, loglik_bs) pars1a <- pars1 @@ -45,14 +45,14 @@ test_that("odeint solvers give the same result as deSolve solvers", { loglik_lsoda_R_Inf <- DAISIE_loglik_all(pars1a, pars2, Galapagos_datalist_2types, methode = methode) methode <- 'lsoda' loglik_lsoda_F_Inf <- DAISIE_loglik_all(pars1a, pars2, Galapagos_datalist_2types, methode = methode) - expect_equal(loglik_lsoda_R_Inf,loglik_lsoda_F_Inf) + testthat::expect_equal(loglik_lsoda_R_Inf,loglik_lsoda_F_Inf) methode <- 'deSolve_R::lsodes' loglik_lsodes_R_Inf <- DAISIE_loglik_all(pars1a, pars2, Galapagos_datalist_2types, methode = methode) methode <- 'lsodes' loglik_lsodes_F_Inf <- DAISIE_loglik_all(pars1a, pars2, Galapagos_datalist_2types, methode = methode) - expect_equal(loglik_lsodes_R_Inf,loglik_lsodes_F_Inf) + testthat::expect_equal(loglik_lsodes_R_Inf,loglik_lsodes_F_Inf) - expect_equal(loglik_lsoda_R_Inf,loglik_lsoda_R, tol = 1E-4) - expect_equal(loglik_lsodes_R_Inf,loglik_lsodes_R, tol = 1E-4) + testthat::expect_equal(loglik_lsoda_R_Inf,loglik_lsoda_R, tol = 1E-4) + testthat::expect_equal(loglik_lsodes_R_Inf,loglik_lsodes_R, tol = 1E-4) }) From 2d646fd5094cd7d65879553d37564038e6e7661d Mon Sep 17 00:00:00 2001 From: Pedro Santos Neves <10762799+Neves-P@users.noreply.github.com> Date: Sun, 8 Oct 2023 12:27:55 +0200 Subject: [PATCH 56/70] use default solver [run ci] --- tests/testthat/test-integration_DAISIE.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index aac33888..8e07a601 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -200,9 +200,8 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial idparsopt = 1:5, parsfix = 0.1, idparsfix = 6, - verbose = 0, + verbose = 0 # verbose = 3, - methode = "deSolve_R::lsodes" ) # ) From 2ff26c63d2bf7c913f5e6badd29ee83743a3111d Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 12:49:15 +0200 Subject: [PATCH 57/70] Adding testthat:: [run ci] --- tests/testthat/test-DAISIE_ExpEIN.R | 22 +- tests/testthat/test-DAISIE_ML1.R | 4 +- tests/testthat/test-DAISIE_ML2.R | 4 +- tests/testthat/test-DAISIE_ML4.R | 4 +- tests/testthat/test-DAISIE_ML_CS.R | 10 +- tests/testthat/test-DAISIE_ONEcolonist.R | 126 ++++++------ .../test-DAISIE_convert_to_classic_plot.R | 2 +- tests/testthat/test-DAISIE_dataprep.R | 18 +- .../testthat/test-DAISIE_extract_stt_median.R | 2 +- tests/testthat/test-DAISIE_format_CS.R | 88 ++++---- .../test-DAISIE_format_CS_sampled_stt.R | 40 ++-- tests/testthat/test-DAISIE_format_CS_trait.R | 2 +- tests/testthat/test-DAISIE_format_GW.R | 10 +- tests/testthat/test-DAISIE_format_IW.R | 38 ++-- .../testthat/test-DAISIE_format_IW_full_stt.R | 70 +++---- .../test-DAISIE_format_IW_sampled_stt.R | 26 +-- tests/testthat/test-DAISIE_loglik_CS_M1.R | 20 +- tests/testthat/test-DAISIE_loglik_integrate.R | 6 +- tests/testthat/test-DAISIE_sim_core_cr.R | 30 +-- .../testthat/test-DAISIE_sim_core_cr_shift.R | 6 +- .../testthat/test-DAISIE_sim_core_time_dep.R | 22 +- .../testthat/test-DAISIE_sim_core_trait_dep.R | 8 +- tests/testthat/test-DAISIE_sim_cr.R | 72 ++++--- tests/testthat/test-DAISIE_sim_relaxed_rate.R | 190 +++++++++--------- tests/testthat/test-DAISIE_sim_time_dep.R | 28 +-- tests/testthat/test-DAISIE_sim_trait_dep.R | 16 +- tests/testthat/test-DAISIE_sumstats_rates.R | 2 +- tests/testthat/test-DAISIE_utils.R | 122 +++++------ tests/testthat/test-are_max_rates_gt_rates.R | 16 +- tests/testthat/test-are_rates.R | 68 +++---- tests/testthat/test-are_trait_pars.R | 2 +- tests/testthat/test-create_area_pars.R | 6 +- tests/testthat/test-create_trait_pars.R | 4 +- tests/testthat/test-get_ana_rate.R | 2 +- tests/testthat/test-get_clado_rate.R | 8 +- tests/testthat/test-get_ext_rate.R | 4 +- tests/testthat/test-get_immig_rate.R | 6 +- .../testthat/test-is_island_ontogeny_input.R | 8 +- tests/testthat/test-is_sea_level_input.R | 8 +- tests/testthat/test-is_simulation_outputs.R | 10 +- tests/testthat/test-island_area.R | 10 +- tests/testthat/test-odeint.R | 2 +- tests/testthat/test-printing.R | 28 +-- .../testthat/test-rosenbrock_abm1_steppers.R | 4 +- tests/testthat/test-time_dep_vs_cr.R | 4 +- tests/testthat/test-update_max_rates.R | 12 +- tests/testthat/test-update_rates.R | 12 +- 47 files changed, 600 insertions(+), 602 deletions(-) diff --git a/tests/testthat/test-DAISIE_ExpEIN.R b/tests/testthat/test-DAISIE_ExpEIN.R index 9dae2213..88c4a370 100644 --- a/tests/testthat/test-DAISIE_ExpEIN.R +++ b/tests/testthat/test-DAISIE_ExpEIN.R @@ -1,5 +1,5 @@ test_that("use", { - expect_silent(DAISIE_ExpEIN( + testthat::expect_silent(DAISIE_ExpEIN( t = 4, pars = c(0.5, 0.1, Inf, 0.01, 0.4), M = 1000 @@ -12,13 +12,13 @@ test_that("output is named list of length 3", { pars = c(0.5, 0.1, Inf, 0.01, 0.4), M = 1000 ) - expect_true( + testthat::expect_true( is.list(ExpEIN_out) ) - expect_length( + testthat::expect_length( ExpEIN_out, 3 ) - expect_equal( + testthat::expect_equal( names(ExpEIN_out), c("ExpE", "ExpI", "ExpN") ) }) @@ -29,13 +29,13 @@ test_that("use with type2", { pars = c(0.5, 0.1, Inf, 0.01, 0.4, 0.7, 0.2, Inf, 0.05, 0.1, 0.1), M = 1000 ) - expect_true( + testthat::expect_true( is.list(ExpEIN_out) ) - expect_length( + testthat::expect_length( ExpEIN_out, 3 ) - expect_equal( + testthat::expect_equal( names(ExpEIN_out), c("ExpE", "ExpI", "ExpN") ) }) @@ -46,13 +46,13 @@ test_that("use with t == Inf", { pars = c(0.5, 0.1, Inf, 0.01, 0.4), M = 1000 ) - expect_true( + testthat::expect_true( is.list(ExpEIN_out) ) - expect_length( + testthat::expect_length( ExpEIN_out, 3 ) - expect_equal( + testthat::expect_equal( names(ExpEIN_out), c("ExpE", "ExpI", "ExpN") ) }) @@ -60,7 +60,7 @@ test_that("use with t == Inf", { test_that("abuse", { - expect_error(DAISIE_ExpEIN( + testthat::expect_error(DAISIE_ExpEIN( t = 4, pars = "nonsense", M = 1000 diff --git a/tests/testthat/test-DAISIE_ML1.R b/tests/testthat/test-DAISIE_ML1.R index c12a1a6d..291e783f 100644 --- a/tests/testthat/test-DAISIE_ML1.R +++ b/tests/testthat/test-DAISIE_ML1.R @@ -32,7 +32,7 @@ test_that("use", { df = 5L, conv = 0L ) - expect_equal(tested_MLE, expected_MLE) + testthat::expect_equal(tested_MLE, expected_MLE) }) test_that("abuse", { @@ -45,7 +45,7 @@ test_that("abuse", { idparsopt <- 1:5 parsfix <- NULL idparsfix <- NULL - expect_error( + testthat::expect_error( DAISIE_ML1( datalist = "nonsense", initparsopt = initparsopt, diff --git a/tests/testthat/test-DAISIE_ML2.R b/tests/testthat/test-DAISIE_ML2.R index 58af6660..38635aa0 100644 --- a/tests/testthat/test-DAISIE_ML2.R +++ b/tests/testthat/test-DAISIE_ML2.R @@ -52,14 +52,14 @@ test_that("use", { df = c(5L, 5L, 5L, 5L), conv = c(0L, 0L, 0L, 0L) ) - expect_equal(tested_MLE, expected_MLE) + testthat::expect_equal(tested_MLE, expected_MLE) }) test_that("abuse", { skip_if(Sys.getenv("CI") == "", message = "Run only on CI") skip_on_cran() - expect_error(tested_MLE <- DAISIE_ML2( + testthat::expect_error(tested_MLE <- DAISIE_ML2( datalist = "nonsense", initparsopt = c( 1.053151832, diff --git a/tests/testthat/test-DAISIE_ML4.R b/tests/testthat/test-DAISIE_ML4.R index f5aec0ab..96458c2c 100644 --- a/tests/testthat/test-DAISIE_ML4.R +++ b/tests/testthat/test-DAISIE_ML4.R @@ -14,7 +14,7 @@ test_that("DAISIE_ML4 is silent and produces correct output", { relaxed_par = "extinction", par_sd = 0.1, par_upper_bound = 1)) - expect_equal(2, 2) + testthat::expect_equal(2, 2) }) test_that("DAISIE_loglik_all_choosepar4 is silent and produces correct output", { @@ -39,5 +39,5 @@ test_that("DAISIE_loglik_all_choosepar4 is silent and produces correct output", abstolint = 1e-16, reltolint = 1e-10 )))) - expect_equal(output, -77.50300643925) + testthat::expect_equal(output, -77.50300643925) }) diff --git a/tests/testthat/test-DAISIE_ML_CS.R b/tests/testthat/test-DAISIE_ML_CS.R index a731bded..ee454cbb 100644 --- a/tests/testthat/test-DAISIE_ML_CS.R +++ b/tests/testthat/test-DAISIE_ML_CS.R @@ -11,8 +11,8 @@ test_that("relaxed-rate DAISIE_ML_CS produces correct output", { idparsfix = NULL, ddmodel = 11, CS_version = CS_version) - expect_true(is.numeric(RR_clado)) - expect_true(is.numeric(result$loglik)) + testthat::expect_true(is.numeric(RR_clado)) + testthat::expect_true(is.numeric(result$loglik)) }) test_that("relaxed-rate DAISIE_ML_CS produces correct output using simplex", { @@ -29,8 +29,8 @@ test_that("relaxed-rate DAISIE_ML_CS produces correct output using simplex", { ddmodel = 11, CS_version = CS_version, optimmethod = "simplex") - expect_true(is.numeric(RR_clado)) - expect_true(is.numeric(result$loglik)) + testthat::expect_true(is.numeric(RR_clado)) + testthat::expect_true(is.numeric(result$loglik)) }) test_that("multi-rate DAISIE_ML_CS converges to constant rate", { @@ -54,6 +54,6 @@ test_that("multi-rate DAISIE_ML_CS converges to constant rate", { idparsfix = NULL, ddmodel = 11, CS_version = CS_version) - expected_equal(CR, RR_clado) + testthat::expected_equal(CR, RR_clado) }) diff --git a/tests/testthat/test-DAISIE_ONEcolonist.R b/tests/testthat/test-DAISIE_ONEcolonist.R index 86319784..99958c67 100644 --- a/tests/testthat/test-DAISIE_ONEcolonist.R +++ b/tests/testthat/test-DAISIE_ONEcolonist.R @@ -56,16 +56,16 @@ test_that("DAISIE_ONEcolonist works on an oceanic DAISIE_sim_core", { island_spec = island_spec, stt_table = stt_table ) - expect_equal(result$stt_table, stt_table) - expect_true( + testthat::expect_equal(result$stt_table, stt_table) + testthat::expect_true( all.equal( result$branching_times, c(10.0000000, 9.7444564, 2.6619612, 0.8089492, 0.7551818), tolerance = 1.0e-7 ) ) - expect_equal(result$stac, sim$stac) - expect_equal(result$missing_species, sim$missing_species) + testthat::expect_equal(result$stac, sim$stac) + testthat::expect_equal(result$missing_species, sim$missing_species) }) test_that("DAISIE_ONEcolonist works with >=2 cladogenetic with same ancestor", { @@ -87,7 +87,7 @@ test_that("DAISIE_ONEcolonist works with >=2 cladogenetic with same ancestor", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - expect_silent(out <- DAISIE_sim_core_cr( + testthat::expect_silent(out <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -118,7 +118,7 @@ test_that("DAISIE_ONEcolonist works with >=2 anagenetic with same ancestor", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - expect_silent(out <- DAISIE_sim_core_cr( + testthat::expect_silent(out <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -147,7 +147,7 @@ test_that("DAISIE_ONEcolonist works with >=2 nonendemic with same ancestor", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - expect_silent(out <- DAISIE_sim_core_cr( + testthat::expect_silent(out <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -190,12 +190,12 @@ test_that("DAISIE_ONEcolonist stac and brts works for single colonist", { island_spec = island_spec, stt_table = stt_table ) - expect_equal( + testthat::expect_equal( result$branching_times, c(sim_time, sort(as.numeric(island_spec[, 6]), decreasing = TRUE)) ) # Stac 2 for regular clade on island with no recolonization - expect_equal(result$stac, 2) + testthat::expect_equal(result$stac, 2) }) test_that("DAISIE_ONEcolonist stac and brts works for 1 nonendemic colonist", { @@ -226,19 +226,19 @@ test_that("DAISIE_ONEcolonist stac and brts works for 1 nonendemic colonist", { island_spec = island_spec, stt_table = stt_table ) - expect_equal( + testthat::expect_equal( result$branching_times, c(sim_time, max(as.numeric(island_spec[, 3]))) ) # Stac 3 for recolonisation cases - expect_equal(result$stac, 3) + testthat::expect_equal(result$stac, 3) - expect_equal(result$all_colonisations[[1]]$event_times, c(2, 0.7)) - expect_equal(result$all_colonisations[[1]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[1]]$event_times, c(2, 0.7)) + testthat::expect_equal(result$all_colonisations[[1]]$species_type, "A") - expect_equal(result$all_colonisations[[2]]$event_times, c(2, 0.6)) - expect_equal(result$all_colonisations[[2]]$species_type, "I") + testthat::expect_equal(result$all_colonisations[[2]]$event_times, c(2, 0.6)) + testthat::expect_equal(result$all_colonisations[[2]]$species_type, "I") }) @@ -272,21 +272,21 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic colonists, stt_table = stt_table ) # Only include oldest colonisation time time - expect_equal( + testthat::expect_equal( result$branching_times, c(sim_time, as.numeric(island_spec[, 3])[1:2]) ) # stac 3 for recolonisation cases - expect_equal(result$stac, 3) + testthat::expect_equal(result$stac, 3) - expect_equal(result$all_colonisations[[1]]$event_times, c(2, 0.7)) - expect_equal(result$all_colonisations[[1]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[1]]$event_times, c(2, 0.7)) + testthat::expect_equal(result$all_colonisations[[1]]$species_type, "A") - expect_equal(result$all_colonisations[[2]]$event_times, c(2, 0.6)) - expect_equal(result$all_colonisations[[2]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[2]]$event_times, c(2, 0.6)) + testthat::expect_equal(result$all_colonisations[[2]]$species_type, "A") - expect_equal(result$all_colonisations[[3]]$event_times, c(2, 0.5)) - expect_equal(result$all_colonisations[[3]]$species_type, "I") + testthat::expect_equal(result$all_colonisations[[3]]$event_times, c(2, 0.5)) + testthat::expect_equal(result$all_colonisations[[3]]$species_type, "I") }) test_that("DAISIE_ONEcolonist stac and brts works for 3 endemic colonists", { @@ -323,18 +323,18 @@ test_that("DAISIE_ONEcolonist stac and brts works for 3 endemic colonists", { c(sim_time, as.numeric(island_spec[, 3])[1:2]) ) # stac 3 for recolonisation cases - expect_equal(result$stac, 3) + testthat::expect_equal(result$stac, 3) - expect_length(result$all_colonisations, 3) + testthat::expect_length(result$all_colonisations, 3) - expect_equal(result$all_colonisations[[1]]$event_times, c(2, 0.7)) - expect_equal(result$all_colonisations[[1]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[1]]$event_times, c(2, 0.7)) + testthat::expect_equal(result$all_colonisations[[1]]$species_type, "A") - expect_equal(result$all_colonisations[[2]]$event_times, c(2, 0.6)) - expect_equal(result$all_colonisations[[2]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[2]]$event_times, c(2, 0.6)) + testthat::expect_equal(result$all_colonisations[[2]]$species_type, "A") - expect_equal(result$all_colonisations[[3]]$event_times, c(2, 0.5)) - expect_equal(result$all_colonisations[[3]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[3]]$event_times, c(2, 0.5)) + testthat::expect_equal(result$all_colonisations[[3]]$species_type, "A") }) @@ -387,31 +387,31 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades", { ) btimes <- sort(as.numeric(island_spec[, 6]), decreasing = TRUE) btimes_sans_yng_col <- btimes[-4] - expect_equal( + testthat::expect_equal( result$branching_times, c(sim_time, btimes_sans_yng_col) ) - expect_length(result$all_colonisations, 2) + testthat::expect_length(result$all_colonisations, 2) # stac 3 for recolonisation cases - expect_equal(result$stac, 3) + testthat::expect_equal(result$stac, 3) # all_colonisations - expect_equal(result$all_colonisations[[1]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[1]]$event_times, c( 2.0, 1.13468671408026, 0.96545899791969, 0.68696590746724 )) - expect_equal(result$all_colonisations[[1]]$species_type, "C") + testthat::expect_equal(result$all_colonisations[[1]]$species_type, "C") - expect_equal(result$all_colonisations[[2]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[2]]$event_times, c( 2.0, 0.67395467208331, 0.34198900695798 )) - expect_equal(result$all_colonisations[[2]]$species_type, "C") + testthat::expect_equal(result$all_colonisations[[2]]$species_type, "C") }) test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades, @@ -468,37 +468,37 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades, ) # Here, branching times already exclude youngest colononisation btimes_sans_yng_col <- sort(as.numeric(island_spec[, 6]), decreasing = TRUE) - expect_equal( + testthat::expect_equal( result$branching_times, c(sim_time, btimes_sans_yng_col) ) - expect_length(result$all_colonisations, 3) + testthat::expect_length(result$all_colonisations, 3) # stac 3 for recolonisation cases - expect_equal(result$stac, 3) + testthat::expect_equal(result$stac, 3) # all_colonisations - expect_equal(result$all_colonisations[[1]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[1]]$event_times, c( 2.0, 1.13468671408026, 0.96545899791969, 0.68696590746724 )) - expect_equal(result$all_colonisations[[1]]$species_type, "C") + testthat::expect_equal(result$all_colonisations[[1]]$species_type, "C") - expect_equal(result$all_colonisations[[2]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[2]]$event_times, c( 2.0, 0.67395467208331, 0.34198900695798 )) - expect_equal(result$all_colonisations[[2]]$species_type, "C") + testthat::expect_equal(result$all_colonisations[[2]]$species_type, "C") - expect_equal(result$all_colonisations[[3]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[3]]$event_times, c( 2.0, 0.47395467208331 )) - expect_equal(result$all_colonisations[[3]]$species_type, "I") + testthat::expect_equal(result$all_colonisations[[3]]$species_type, "I") }) test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades, @@ -555,35 +555,35 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades, ) btimes_sans_yng_col <- c(2.0, 1.1346867, 0.9654590, 0.7, 0.6869659, 0.3419890) - expect_equal( + testthat::expect_equal( result$branching_times, c(btimes_sans_yng_col) ) - expect_length(result$all_colonisations, 3) + testthat::expect_length(result$all_colonisations, 3) # stac 3 for recolonisation cases - expect_equal(result$stac, 3) + testthat::expect_equal(result$stac, 3) # all_colonisations - expect_equal(result$all_colonisations[[1]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[1]]$event_times, c( 2.0, 1.13468671408026, 0.96545899791969, 0.68696590746724 )) - expect_equal(result$all_colonisations[[1]]$species_type, "C") + testthat::expect_equal(result$all_colonisations[[1]]$species_type, "C") - expect_equal(result$all_colonisations[[2]]$event_times, c(2.0, 0.7)) - expect_equal(result$all_colonisations[[2]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[2]]$event_times, c(2.0, 0.7)) + testthat::expect_equal(result$all_colonisations[[2]]$species_type, "A") - expect_equal(result$all_colonisations[[3]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[3]]$event_times, c( 2.0, 0.67395467208331, 0.34198900695798 )) - expect_equal(result$all_colonisations[[3]]$species_type, "C") + testthat::expect_equal(result$all_colonisations[[3]]$species_type, "C") }) @@ -618,27 +618,27 @@ test_that("DAISIE_ONEcolonist stac and brts works for 1 anagenetic clade from # island_spec "4" "1" "6.33541590408438" "A" NA NA "Clado_extinct" # "1" "1" "0.643802977852591" "I" NA NA NA - expect_equal( + testthat::expect_equal( result$branching_times, c(sim_time, 6.33541590408438) ) - expect_length(result$all_colonisations, 2) + testthat::expect_length(result$all_colonisations, 2) # stac 3 for recolonisation cases - expect_equal(result$stac, 3) + testthat::expect_equal(result$stac, 3) # all_colonisations - expect_equal(result$all_colonisations[[1]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[1]]$event_times, c( 10.0, 6.33541590408438 )) - expect_equal(result$all_colonisations[[1]]$species_type, "A") + testthat::expect_equal(result$all_colonisations[[1]]$species_type, "A") - expect_equal(result$all_colonisations[[2]]$event_times, c( + testthat::expect_equal(result$all_colonisations[[2]]$event_times, c( 10.0, 0.643802977852591) ) - expect_equal(result$all_colonisations[[2]]$species_type, "I") + testthat::expect_equal(result$all_colonisations[[2]]$species_type, "I") }) diff --git a/tests/testthat/test-DAISIE_convert_to_classic_plot.R b/tests/testthat/test-DAISIE_convert_to_classic_plot.R index 1ca8c389..f5933fb1 100644 --- a/tests/testthat/test-DAISIE_convert_to_classic_plot.R +++ b/tests/testthat/test-DAISIE_convert_to_classic_plot.R @@ -1,5 +1,5 @@ test_that("abuse", { - expect_error( + testthat::expect_error( DAISIE_convert_to_classic_plot("nonsense"), "'simulation_outputs' should be a set of simulation outputs" ) diff --git a/tests/testthat/test-DAISIE_dataprep.R b/tests/testthat/test-DAISIE_dataprep.R index 630ed3b8..a9b1f9e6 100644 --- a/tests/testthat/test-DAISIE_dataprep.R +++ b/tests/testthat/test-DAISIE_dataprep.R @@ -4,9 +4,9 @@ test_that("DAISIE_dataprep produces a named list of length 9 for one type", { island_age = 4, M = 1000, verbose = FALSE) - expect_length(output, 9) - expect_true(is.list(output)) - expect_named(output[[1]], expected = c("island_age", "not_present")) + testthat::expect_length(output, 9) + testthat::expect_true(is.list(output)) + testthat::expect_named(output[[1]], expected = c("island_age", "not_present")) }) test_that("DAISIE_dataprep produces a named list of length 9 for two types", { @@ -17,9 +17,9 @@ test_that("DAISIE_dataprep produces a named list of length 9 for two types", { number_clade_types = 2, list_type2_clades = "Finches", verbose = FALSE) - expect_length(output, 9) - expect_true(is.list(output)) - expect_named(output[[1]], expected = c("island_age", + testthat::expect_length(output, 9) + testthat::expect_true(is.list(output)) + testthat::expect_named(output[[1]], expected = c("island_age", "not_present_type1", "not_present_type2")) }) @@ -34,9 +34,9 @@ test_that("DAISIE_dataprep produces a named list of length 9 for two types list_type2_clades = "Finches", prop_type2_pool = 0.163, verbose = FALSE) - expect_length(output, 9) - expect_true(is.list(output)) - expect_named(output[[1]], expected = c("island_age", + testthat::expect_length(output, 9) + testthat::expect_true(is.list(output)) + testthat::expect_named(output[[1]], expected = c("island_age", "not_present_type1", "not_present_type2")) }) diff --git a/tests/testthat/test-DAISIE_extract_stt_median.R b/tests/testthat/test-DAISIE_extract_stt_median.R index f4420d24..d2ba8281 100644 --- a/tests/testthat/test-DAISIE_extract_stt_median.R +++ b/tests/testthat/test-DAISIE_extract_stt_median.R @@ -12,5 +12,5 @@ test_that("use", { Endemic = c(0, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 21, 22, 23, 24, 25), # nolint keep this one line Total = c(0, 1, 2, 4, 5, 6, 7, 9, 10, 10, 11.5, 13, 14, 15, 15, 17, 18, 19, 20, 22, 22, 23, 24, 24, 26, 26) # nolint keep this one line ) - expect_equal(created, expected) + testthat::expect_equal(created, expected) }) diff --git a/tests/testthat/test-DAISIE_format_CS.R b/tests/testthat/test-DAISIE_format_CS.R index ba91e0a0..fc6877d0 100644 --- a/tests/testthat/test-DAISIE_format_CS.R +++ b/tests/testthat/test-DAISIE_format_CS.R @@ -24,7 +24,7 @@ test_that("silent with empty island with correct output", { ) ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, @@ -42,7 +42,7 @@ test_that("silent with empty island with correct output", { expected_CS_format[[1]][[1]] <- list(island_age = 1, not_present = 1, stt_all = stt_all) - expect_identical(formatted_CS_sim, expected_CS_format) + testthat::expect_identical(formatted_CS_sim, expected_CS_format) }) test_that("silent with non-empty island with correct output", { @@ -70,7 +70,7 @@ test_that("silent with non-empty island with correct output", { island_gradient_angle = 0) ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( # nolint island_replicates = island_replicates, time = time, @@ -94,7 +94,7 @@ test_that("silent with non-empty island with correct output", { 0.029668240213840), stac = 2, missing_species = 0) - expect_equal(formatted_CS_sim, expected_CS_format) + testthat::expect_equal(formatted_CS_sim, expected_CS_format) }) test_that("output with empty island and verbose = TRUE", { @@ -122,7 +122,7 @@ test_that("output with empty island and verbose = TRUE", { island_gradient_angle = 0) ) island_replicates[[1]] <- out - expect_message( + testthat::expect_message( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, @@ -161,7 +161,7 @@ test_that("silent with non-empty 2 type island", { sea_level_frequency = 0, island_gradient_angle = 0), verbose = FALSE) - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, @@ -200,7 +200,7 @@ test_that("silent with non-empty 2 type island full stt", { sea_level_frequency = 0, island_gradient_angle = 0) ) - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, @@ -211,7 +211,7 @@ test_that("silent with non-empty 2 type island full stt", { }) test_that("abuse", { - expect_error( + testthat::expect_error( DAISIE_format_CS( island_replicates = "nonsense", time = "nonsense", @@ -248,7 +248,7 @@ test_that("use full stt", { island_gradient_angle = 0) ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, @@ -257,57 +257,57 @@ test_that("use full stt", { verbose = verbose ) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$island_age, 5 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$not_present, 0 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[2, ], c(Time = 4.62240908343582735, nI = 1.0, nA = 0.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[5, ], c(Time = 3.81548257687248871, nI = 0.0, nA = 1.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[11, ], c(Time = 2.22760715636035123, nI = 1.0, nA = 0.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$branching_times, c(5.0000000000000000, 2.22760715636035, 1.3487418169725700, 0.0921013811906803) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$stac, 3 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$all_colonisations[[1]]$event_times, c(5.0, 2.22760716) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$all_colonisations[[1]]$species_type, "A" ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$all_colonisations[[2]]$event_times, c(5.0, 1.34874181697257, 0.0921013811906803) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$all_colonisations[[2]]$species_type, "C" ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$missing_species, 0 ) @@ -362,7 +362,7 @@ test_that("use complete stt with ontogeny", { extcutoff = 1000 ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, @@ -372,39 +372,39 @@ test_that("use complete stt with ontogeny", { ) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$island_age, 10 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$not_present, 0 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[5, ], c(Time = 6.2738223342025243, nI = 1.0, nA = 0.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[12, ], c(Time = 3.2073998327641329, nI = 1.0, nA = 2.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[16, ], c(Time = 2.1527893059827958, nI = 1.0, nA = 0.0, nC = 4.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$branching_times, c(10.00000000000000, 6.27382233420251989, 4.99629097366935, 2.14112644569665012, 1.13725415915635009, 0.54321135189076997, 0.15055819094851100) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$stac, 3 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$missing_species, 0 ) @@ -447,7 +447,7 @@ test_that("full stt works with multiple replicates", { nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, @@ -495,7 +495,7 @@ test_that("full stt works with empty island", { } island_replicates[[rep]] <- full_list } - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, @@ -539,7 +539,7 @@ test_that("full stt with two trait states", { trait_pars = trait_pars ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, @@ -549,50 +549,50 @@ test_that("full stt with two trait states", { trait_pars = trait_pars ) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$island_age, 5 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$not_present, 0 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_two_states[2, ], c(Time = 4.24481817, nI = 0.0, nA = 0.0, nC = 0.0, nI2 = 1.0, nA2 = 0.0, nC2 = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_two_states[5, ], c(Time = 3.61806444, nI = 0.0, nA = 0.0, nC = 0.0, nI2 = 1.0, nA2 = 0.0, nC2 = 2.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_two_states[11, ], c(Time = 1.17170697, nI = 0.0, nA = 0.0, nC = 0.0, nI2 = 0.0, nA2 = 3.0, nC2 = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[2, ], c(Time = 4.24481817, nI = 1.0, nA = 0.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[5, ], c(Time = 3.61806444, nI = 1.0, nA = 0.0, nC = 2.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[11, ], c(Time = 1.17170697, nI = 0.0, nA = 3.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$branching_times, c(5, 4.24481817, 3.61806444, 1.25876988, 0.01277218) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$stac, 3 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$missing_species, 0 ) diff --git a/tests/testthat/test-DAISIE_format_CS_sampled_stt.R b/tests/testthat/test-DAISIE_format_CS_sampled_stt.R index 3b8637b4..e22fe3f5 100644 --- a/tests/testthat/test-DAISIE_format_CS_sampled_stt.R +++ b/tests/testthat/test-DAISIE_format_CS_sampled_stt.R @@ -28,7 +28,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic island (same arguments nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = time, @@ -52,7 +52,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic island (same arguments 0.029668240213840), stac = 2, missing_species = 0) - expect_equal(formatted_CS_sim, expected_CS_format) + testthat::expect_equal(formatted_CS_sim, expected_CS_format) }) test_that("sampled stt, 1 type, geodynamics, oceanic island (same arguments as @@ -105,7 +105,7 @@ test_that("sampled stt, 1 type, geodynamics, oceanic island (same arguments as nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, @@ -115,38 +115,38 @@ test_that("sampled stt, 1 type, geodynamics, oceanic island (same arguments as ) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$island_age, 5 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$not_present, 0 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[5, ], c(Time = 4.2, nI = 0.0, nA = 0.0, nC = 0.0, present = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[12, ], c(Time = 2.8, nI = 1.0, nA = 0.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[1]]$stt_all[25, ], c(Time = 0.2, nI = 0.0, nA = 2.0, nC = 0.0, present = 1.0) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$branching_times, c(5.00000000000000, 0.57929405393928002) ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$stac, 2 ) - expect_equal( + testthat::expect_equal( formatted_CS_sim[[1]][[2]]$missing_species, 0 ) @@ -183,7 +183,7 @@ test_that("sampled stt, 2 type, no geodynamics, oceanic island (same arguments hyper_pars = hyper_pars, verbose = FALSE ) - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, @@ -193,7 +193,7 @@ test_that("sampled stt, 2 type, no geodynamics, oceanic island (same arguments ) ) - expect_equal( + testthat::expect_equal( names(formatted_CS_sim[[1]][[1]]), c( "island_age", @@ -205,7 +205,7 @@ test_that("sampled stt, 2 type, no geodynamics, oceanic island (same arguments ) ) - expect_equal( + testthat::expect_equal( names(formatted_CS_sim[[1]][[2]]), c( "branching_times", @@ -216,18 +216,18 @@ test_that("sampled stt, 2 type, no geodynamics, oceanic island (same arguments ) ) - expect_equal( + testthat::expect_equal( length(formatted_CS_sim[[1]]), 8 ) # Sampled STT has the correct size - expect_equal( + testthat::expect_equal( dim(formatted_CS_sim[[1]][[1]]$stt_all), c(26, 5) ) - expect_equal( + testthat::expect_equal( dim(formatted_CS_sim[[1]][[1]]$stt_type1), c(26, 5) ) - expect_equal( + testthat::expect_equal( dim(formatted_CS_sim[[1]][[1]]$stt_type2), c(26, 5) ) }) @@ -267,7 +267,7 @@ test_that("sampled stt, 1 type, no geodynamics, nonoceanic (same arguments as nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, @@ -319,7 +319,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic (same arguments as island_replicates[[rep]] <- full_list } - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, diff --git a/tests/testthat/test-DAISIE_format_CS_trait.R b/tests/testthat/test-DAISIE_format_CS_trait.R index 497c2c03..aabcb7c4 100644 --- a/tests/testthat/test-DAISIE_format_CS_trait.R +++ b/tests/testthat/test-DAISIE_format_CS_trait.R @@ -84,7 +84,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic, two trait states } island_replicates[[rep]] <- full_list } - expect_silent( + testthat::expect_silent( formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, diff --git a/tests/testthat/test-DAISIE_format_GW.R b/tests/testthat/test-DAISIE_format_GW.R index 769e1bc1..5385dc13 100644 --- a/tests/testthat/test-DAISIE_format_GW.R +++ b/tests/testthat/test-DAISIE_format_GW.R @@ -27,7 +27,7 @@ test_that("silent with empty island with correct output", { nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_GW_sim <- DAISIE_format_GW( island_replicates = island_replicates, time = time, @@ -46,7 +46,7 @@ test_that("silent with empty island with correct output", { expected_GW_format[[1]][[1]] <- list(island_age = 1, not_present = 1, stt_all = stt_all) - expect_identical(formatted_GW_sim, expected_GW_format) + testthat::expect_identical(formatted_GW_sim, expected_GW_format) }) test_that("silent with non-empty island with correct output", { @@ -78,7 +78,7 @@ test_that("silent with non-empty island with correct output", { nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_silent( + testthat::expect_silent( formatted_GW_sim <- DAISIE_format_GW( island_replicates = island_replicates, time = time, @@ -119,7 +119,7 @@ test_that("output with empty island and verbose = TRUE", { nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_message( + testthat::expect_message( formatted_GW_sim <- DAISIE_format_GW( island_replicates = island_replicates, time = time, @@ -133,5 +133,5 @@ test_that("output with empty island and verbose = TRUE", { }) test_that("abuse", { - expect_error(DAISIE_format_GW("nonsense")) + testthat::expect_error(DAISIE_format_GW("nonsense")) }) diff --git a/tests/testthat/test-DAISIE_format_IW.R b/tests/testthat/test-DAISIE_format_IW.R index 17d43c1d..d257aa3a 100644 --- a/tests/testthat/test-DAISIE_format_IW.R +++ b/tests/testthat/test-DAISIE_format_IW.R @@ -25,7 +25,7 @@ test_that("silent with empty island with correct output", { hyper_pars = hyper_pars, nonoceanic_pars = nonoceanic_pars ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -47,7 +47,7 @@ test_that("silent with empty island with correct output", { not_present = 10, stt_all = stt_all, brts_table = brts_table) - expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) + testthat::expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) }) test_that("silent with non-empty island with correct output", { @@ -76,7 +76,7 @@ test_that("silent with non-empty island with correct output", { hyper_pars = hyper_pars, nonoceanic_pars = nonoceanic_pars ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -117,7 +117,7 @@ test_that("silent with non-empty island with correct output", { 0.5288428248966160), stac = 4, missing_species = 0) - expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) + testthat::expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) }) test_that("DAISIE_format_IW prints when verbose = TRUE", { @@ -146,7 +146,7 @@ test_that("DAISIE_format_IW prints when verbose = TRUE", { hyper_pars = hyper_pars, nonoceanic_pars = nonoceanic_pars ) - expect_message( + testthat::expect_message( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -184,7 +184,7 @@ test_that("silent with empty nonoceanic island with correct output", { hyper_pars = hyper_pars, nonoceanic_pars = nonoceanic_pars ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -206,7 +206,7 @@ test_that("silent with empty nonoceanic island with correct output", { not_present = 10, stt_all = stt_all, brts_table = brts_table) - expect_equal(formatted_IW_sim, expected_IW_format) + testthat::expect_equal(formatted_IW_sim, expected_IW_format) }) test_that("silent with non-empty nonoceanic island with @@ -237,7 +237,7 @@ test_that("silent with non-empty nonoceanic island with area_pars = area_pars, hyper_pars = hyper_pars ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -267,7 +267,7 @@ test_that("silent with non-empty nonoceanic island with expected_IW_format[[1]][[3]] <- list(branching_times = c(1, 1), stac = 2, missing_species = 0) - expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) + testthat::expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) }) test_that("silent with non-empty nonoceanic island with @@ -298,7 +298,7 @@ test_that("silent with non-empty nonoceanic island with area_pars = area_pars, hyper_pars = hyper_pars ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -328,7 +328,7 @@ test_that("silent with non-empty nonoceanic island with expected_IW_format[[1]][[3]] <- list(branching_times = c(1, 1), stac = 2, missing_species = 0) - expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) + testthat::expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) }) test_that("add_brt_table output is correct when length(island) == 1", { @@ -353,7 +353,7 @@ test_that("add_brt_table output is correct when length(island) == 1", { init_nonend_spec = 0, init_end_spec = 0, brts_table = brt_table) - expect_equal(formatted_brt, expected_brt) + testthat::expect_equal(formatted_brt, expected_brt) }) test_that("add_brt_table output is correct when length(island) != 1", { @@ -406,18 +406,18 @@ test_that("add_brt_table output is correct when length(island) != 1", { 0.5557734), stac = 4, missing_species = 0) - expect_equal(formatted_brt, expected_brt) + testthat::expect_equal(formatted_brt, expected_brt) }) #test_that("add_brt_table output is correct when length(stac1_5s) != 0") #test_that("add_brt_table output is correct when length(stac1_5s) == 0") #test_that("add_brt_table output is correct when length(island_no_stac1or5) != 0") test_that("abuse", { - expect_error(DAISIE_format_IW("nonsense")) + testthat::expect_error(DAISIE_format_IW("nonsense")) }) test_that("abuse", { - expect_error(add_brt_table("nonsense")) + testthat::expect_error(add_brt_table("nonsense")) }) @@ -455,7 +455,7 @@ test_that("silent with empty island with correct output", { trait_pars = trait_pars, mainland_n = mainland_n ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -478,7 +478,7 @@ test_that("silent with empty island with correct output", { not_present = 20, stt_all = stt_all, brts_table = brts_table) - expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) + testthat::expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) }) test_that("silent when species with two trait states with @@ -521,7 +521,7 @@ test_that("silent when species with two trait states with island_gradient_angle = 0), extcutoff = extcutoff ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, @@ -561,5 +561,5 @@ test_that("silent when species with two trait states with stac = 2, missing_species = 0 ) - expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) + testthat::expect_equal(formatted_IW_sim, expected_IW_format, tolerance = 1e-7) }) diff --git a/tests/testthat/test-DAISIE_format_IW_full_stt.R b/tests/testthat/test-DAISIE_format_IW_full_stt.R index a8cefdc4..6cd03312 100644 --- a/tests/testthat/test-DAISIE_format_IW_full_stt.R +++ b/tests/testthat/test-DAISIE_format_IW_full_stt.R @@ -41,7 +41,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state number_present <- length(present) } } - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW_full_stt( island_replicates = island_replicates, total_time = total_time, @@ -50,19 +50,19 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state ) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$island_age, 1 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$not_present, 99 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[2, ], c(Time = 0.244818166871655, nI = 1.0, nA = 0.0, nC = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[4, ], c(Time = 0.0, nI = 0.0, nA = 1.0, nC = 0.0) ) @@ -72,38 +72,38 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state ) colnames(expected_brts_table) <- c("brt", "clade", "event", "endemic", "col") rownames(expected_brts_table) <- c("", "brts_table") - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$brts_table, expected_brts_table ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$branching_times, c(1.000000000000000, 0.244818166871655) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$stac, 2 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$missing_species, 0 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[1]]$island_age, 1 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[1]]$not_present, 99 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[1]]$stt_all[2, ], c(Time = 0.741771912202239, nI = 1.0, nA = 0.0, nC = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[1]]$stt_all[3, ], c(Time = 0.0, nI = 1.0, nA = 0.0, nC = 0.0) ) @@ -114,22 +114,22 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state ) colnames(expected_brts_table) <- c("brt", "clade", "event", "endemic", "col") rownames(expected_brts_table) <- c("", "brts_table") - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[1]]$brts_table, expected_brts_table ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[2]]$branching_times, c(1.000000000000000, 0.741771912202239) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[2]]$stac, 4 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[2]][[2]]$missing_species, 0 ) @@ -201,7 +201,7 @@ test_that("complete stt, 1 type, geodynamics, oceanic island, one trait state } } - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW_full_stt( island_replicates = island_replicates, total_time = total_time, @@ -210,40 +210,40 @@ test_that("complete stt, 1 type, geodynamics, oceanic island, one trait state ) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$island_age, 5 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$not_present, 90 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[2, ], c(Time = 4.99244818166872, nI = 1.0, nA = 0.0, nC = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[5, ], c(Time = 4.79587602350116, nI = 0.0, nA = 0.0, nC = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$branching_times, c(5.00000000000000, 1.38252473752213) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$stac, 4 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$missing_species, 0 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$brts_table[1, ], c(brt = 5, clade = 0, event = 0, endemic = NA, col = NA) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$brts_table[5, ], c(brt = 0.83094531417507, clade = 4, event = 1, endemic = 1, col = NA) ) @@ -301,9 +301,9 @@ test_that("complete stt, 1 type, no geodynamics, nonoceanic, one trait state } } # stt is not empty at start - expect_gt(sum(island_replicates[[1]]$stt_table[1, ]), expected = total_time) - expect_gt(sum(island_replicates[[2]]$stt_table[1, ]), expected = total_time) - expect_silent( + testthat::expect_gt(sum(island_replicates[[1]]$stt_table[1, ]), expected = total_time) + testthat::expect_gt(sum(island_replicates[[2]]$stt_table[1, ]), expected = total_time) + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW_full_stt( island_replicates = island_replicates, total_time = total_time, @@ -357,7 +357,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait number_present <- length(present) } } - expect_message( + testthat::expect_message( formatted_IW_sim <- DAISIE_format_IW_full_stt( island_replicates = island_replicates, total_time = total_time, @@ -400,7 +400,7 @@ test_that("when no colonization happens returns 0", { island_replicates <- list(out) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW_full_stt( island_replicates = island_replicates, total_time = total_time, @@ -409,15 +409,15 @@ test_that("when no colonization happens returns 0", { ) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$island_age, 1 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$not_present, 100 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[2, ], c(Time = 0, nI = 0.0, nA = 0.0, nC = 0.0) ) diff --git a/tests/testthat/test-DAISIE_format_IW_sampled_stt.R b/tests/testthat/test-DAISIE_format_IW_sampled_stt.R index 86e18c07..34ff22bf 100644 --- a/tests/testthat/test-DAISIE_format_IW_sampled_stt.R +++ b/tests/testthat/test-DAISIE_format_IW_sampled_stt.R @@ -41,7 +41,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic island (same arguments a number_present <- length(present) } } - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW_sampled_stt( island_replicates = island_replicates, total_time = total_time, @@ -78,7 +78,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic island (same arguments a 0.029668240213840), stac = 2, missing_species = 0) - expect_equal(object = formatted_IW_sim, expected = expected_IW_format) + testthat::expect_equal(object = formatted_IW_sim, expected = expected_IW_format) }) @@ -130,7 +130,7 @@ test_that("sampled stt, 1 type, geodynamics, oceanic island (same arguments as n Amin = Amin, nonoceanic_pars = nonoceanic_pars ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW_sampled_stt( island_replicates = island_replicates, total_time = total_time, @@ -140,38 +140,38 @@ test_that("sampled stt, 1 type, geodynamics, oceanic island (same arguments as n ) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$island_age, total_time ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$not_present, 90 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[5, ], c(Time = 0.84, nI = 1.0, nA = 0.0, nC = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[12, ], c(Time = 0.56, nI = 4.0, nA = 1.0, nC = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[1]]$stt_all[25, ], c(Time = 0.04, nI = 7.0, nA = 2.0, nC = 0.0) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$branching_times, c(1.00000000000000, 0.982693734281605) ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$stac, 2 ) - expect_equal( + testthat::expect_equal( formatted_IW_sim[[1]][[2]]$missing_species, 0 ) @@ -208,7 +208,7 @@ test_that("sampled stt, 1 type, no geodynamics, nonoceanic (same arguments as ge hyper_pars = hyper_pars, nonoceanic_pars = nonoceanic_pars ) - expect_silent( + testthat::expect_silent( formatted_IW_sim <- DAISIE_format_IW_sampled_stt( island_replicates = island_replicates, total_time = total_time, @@ -217,5 +217,5 @@ test_that("sampled stt, 1 type, no geodynamics, nonoceanic (same arguments as ge verbose = verbose ) ) - expect_gt(sum(formatted_IW_sim[[1]][[1]]$stt_all[1, ]), total_time) + testthat::expect_gt(sum(formatted_IW_sim[[1]][[1]]$stt_all[1, ]), total_time) }) diff --git a/tests/testthat/test-DAISIE_loglik_CS_M1.R b/tests/testthat/test-DAISIE_loglik_CS_M1.R index f5a28301..d23511c1 100644 --- a/tests/testthat/test-DAISIE_loglik_CS_M1.R +++ b/tests/testthat/test-DAISIE_loglik_CS_M1.R @@ -75,17 +75,17 @@ test_that("DAISIE_loglik_CS_M1 produces correct output",{ -5.51422850883622, -6.79274094716205 ) - expect_equal(out_1, expected_out_1) - expect_equal(out_2, expected_out_2) + testthat::expect_equal(out_1, expected_out_1) + testthat::expect_equal(out_2, expected_out_2) # Max_ages at island age should be very close to max ages at very close to # island age - expect_lt(out_1[1] - out_1[2], 1e-3) - expect_lt(out_1[4] - out_1[5], 1e-3) - expect_lt(out_1[7] - out_1[8], 1e-3) - expect_lt(out_1[10] - out_1[11], 1e-3) - expect_lt(out_2[1] - out_2[2], 1e-3) - expect_lt(out_2[4] - out_2[5], 1e-3) - expect_lt(out_2[7] - out_2[8], 1e-3) - expect_lt(out_2[10] - out_2[11], 1e-3) + testthat::expect_lt(out_1[1] - out_1[2], 1e-3) + testthat::expect_lt(out_1[4] - out_1[5], 1e-3) + testthat::expect_lt(out_1[7] - out_1[8], 1e-3) + testthat::expect_lt(out_1[10] - out_1[11], 1e-3) + testthat::expect_lt(out_2[1] - out_2[2], 1e-3) + testthat::expect_lt(out_2[4] - out_2[5], 1e-3) + testthat::expect_lt(out_2[7] - out_2[8], 1e-3) + testthat::expect_lt(out_2[10] - out_2[11], 1e-3) }) diff --git a/tests/testthat/test-DAISIE_loglik_integrate.R b/tests/testthat/test-DAISIE_loglik_integrate.R index 1aad41c9..77cd5a4b 100644 --- a/tests/testthat/test-DAISIE_loglik_integrate.R +++ b/tests/testthat/test-DAISIE_loglik_integrate.R @@ -75,7 +75,7 @@ test_that("DAISIE_loglik_integrand produces correct output", { pick = 1, par_mean = 2.550687345, par_sd = 1) - expect_equal(output, -2.13638048160996) + testthat::expect_equal(output, -2.13638048160996) }) test_that("rho produces correct output", { @@ -83,10 +83,10 @@ test_that("rho produces correct output", { DAISIE_dist_pars = list( par_mean = 1, par_sd = 1)) - expect_equal(output, -0.5) + testthat::expect_equal(output, -0.5) }) test_that("transform_gamma_pars produces correct output", { output <- transform_gamma_pars(par_mean = 1, par_sd = 1) - expect_equal(output, list(shape = 1, scale = 1)) + testthat::expect_equal(output, list(shape = 1, scale = 1)) }) diff --git a/tests/testthat/test-DAISIE_sim_core_cr.R b/tests/testthat/test-DAISIE_sim_core_cr.R index 51527dcc..dd6ad71c 100644 --- a/tests/testthat/test-DAISIE_sim_core_cr.R +++ b/tests/testthat/test-DAISIE_sim_core_cr.R @@ -17,7 +17,7 @@ test_that("Clean run should be silent", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - expect_silent( + testthat::expect_silent( DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, @@ -53,8 +53,8 @@ test_that("A non-oceanic run with non-zero sampling should have native hyper_pars = hyper_pars, nonoceanic_pars = c(0.1, 0.9) ) - expect_gt(nonoceanic_sim$stt_table[1, 2], 0) - expect_gt(nonoceanic_sim$stt_table[1, 3], 0) + testthat::expect_gt(nonoceanic_sim$stt_table[1, 2], 0) + testthat::expect_gt(nonoceanic_sim$stt_table[1, 3], 0) }) @@ -80,16 +80,16 @@ test_that("DAISIE_sim_core output is correct", { hyper_pars = hyper_pars, nonoceanic_pars = nonoceanic_pars ) - expect_true(is.matrix(sim_core$stt_table)) - expect_true(sim_core$stt_table[1, 1] == time) - expect_true(sim_core$stt_table[nrow(sim_core$stt_table), 1] == 0) - expect_true(is.numeric(sim_core$taxon_list[[1]]$branching_times)) - expect_true(is.numeric(sim_core$taxon_list[[1]]$stac)) - expect_true(is.numeric(sim_core$taxon_list[[1]]$missing_species)) - expect_true(length(sim_core$taxon_list) == 5) - expect_true("branching_times" %in% names(sim_core$taxon_list[[1]])) - expect_true("stac" %in% names(sim_core$taxon_list[[1]])) - expect_true("missing_species" %in% names(sim_core$taxon_list[[1]])) + testthat::expect_true(is.matrix(sim_core$stt_table)) + testthat::expect_true(sim_core$stt_table[1, 1] == time) + testthat::expect_true(sim_core$stt_table[nrow(sim_core$stt_table), 1] == 0) + testthat::expect_true(is.numeric(sim_core$taxon_list[[1]]$branching_times)) + testthat::expect_true(is.numeric(sim_core$taxon_list[[1]]$stac)) + testthat::expect_true(is.numeric(sim_core$taxon_list[[1]]$missing_species)) + testthat::expect_true(length(sim_core$taxon_list) == 5) + testthat::expect_true("branching_times" %in% names(sim_core$taxon_list[[1]])) + testthat::expect_true("stac" %in% names(sim_core$taxon_list[[1]])) + testthat::expect_true("missing_species" %in% names(sim_core$taxon_list[[1]])) }) test_that("DAISIE_sim_core with land-bridge starting at time = 0 for CS uses @@ -103,7 +103,7 @@ test_that("DAISIE_sim_core with land-bridge starting at time = 0 for CS uses sea_level_frequency = 0, island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - expect_silent( + testthat::expect_silent( DAISIE_sim_core_cr_shift( time = 10, mainland_n = 1, @@ -127,7 +127,7 @@ test_that("DAISIE_sim_core fails when pars[4] == 0 && island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - expect_error( + testthat::expect_error( DAISIE_sim_core_cr( time = 1, mainland_n = 100, diff --git a/tests/testthat/test-DAISIE_sim_core_cr_shift.R b/tests/testthat/test-DAISIE_sim_core_cr_shift.R index 200f496b..0574aeaf 100644 --- a/tests/testthat/test-DAISIE_sim_core_cr_shift.R +++ b/tests/testthat/test-DAISIE_sim_core_cr_shift.R @@ -11,7 +11,7 @@ test_that("split-rate model runs silent and island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - expect_silent( + testthat::expect_silent( DAISIE_sim_core_cr_shift( time = 10, mainland_n = 1, @@ -35,7 +35,7 @@ test_that("abuse split-rate model with time smaller than shift_times", { island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - expect_error(DAISIE_sim_core_cr_shift( + testthat::expect_error(DAISIE_sim_core_cr_shift( time = 1, mainland_n = 1, pars = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), @@ -55,7 +55,7 @@ test_that("abuse split-rate model with gamma = 0", { island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - expect_error(DAISIE_sim_core_cr_shift( + testthat::expect_error(DAISIE_sim_core_cr_shift( time = 1, mainland_n = 1, pars = c(1, 1, 1, 0, 1, 1, 1, 1, 1, 1), diff --git a/tests/testthat/test-DAISIE_sim_core_time_dep.R b/tests/testthat/test-DAISIE_sim_core_time_dep.R index c2002d18..1bcf19f4 100644 --- a/tests/testthat/test-DAISIE_sim_core_time_dep.R +++ b/tests/testthat/test-DAISIE_sim_core_time_dep.R @@ -27,7 +27,7 @@ test_that("Ontogeny oceanic should run silent IW", { island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(234567890) - expect_silent( + testthat::expect_silent( DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, @@ -74,7 +74,7 @@ test_that("Ontogeny oceanic should run silent CS", { island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(420) - expect_silent( + testthat::expect_silent( DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, @@ -120,7 +120,7 @@ test_that("Ontogeny oceanic with sea level should run silent CS", { island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(439) - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, @@ -135,7 +135,7 @@ test_that("Ontogeny oceanic with sea level should run silent CS", { Amin = Amin ) ) - expect_equal(out$branching_times, c(10, 0.17840243993784999)) + testthat::expect_equal(out$branching_times, c(10, 0.17840243993784999)) }) test_that("all species extinct if island dead", { @@ -182,10 +182,10 @@ test_that("all species extinct if island dead", { extcutoff = 1000 ) last_entry <- ontogeny_sim$stt_table[nrow(ontogeny_sim$stt_table), ] - expect_true(last_entry[1] == 0) - expect_true(last_entry[2] == 0) - expect_true(last_entry[3] == 0) - expect_true(last_entry[4] == 0) + testthat::expect_true(last_entry[1] == 0) + testthat::expect_true(last_entry[2] == 0) + testthat::expect_true(last_entry[3] == 0) + testthat::expect_true(last_entry[4] == 0) }) test_that("!is.null(area_pars) && island_ontogeny == 'const'", { @@ -208,7 +208,7 @@ test_that("!is.null(area_pars) && island_ontogeny == 'const'", { peak <- 1 Amax <- 1 Amin <- 1 - expect_error( + testthat::expect_error( DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, @@ -236,7 +236,7 @@ test_that("(is.null(ext_pars) || is.null(area_pars)) && island_ontogeny <- 1 sea_level <- 1 - expect_error( + testthat::expect_error( DAISIE_sim_core_time_dep( time = time, mainland_n = mainland_n, @@ -254,7 +254,7 @@ test_that("(is.null(ext_pars) || is.null(area_pars)) && test_that("abuse time dependent model with gamma = 0", { - expect_error(DAISIE_sim_core_time_dep( + testthat::expect_error(DAISIE_sim_core_time_dep( time = 1, mainland_n = 1, pars = c(1, 1, 1, 0, 1), diff --git a/tests/testthat/test-DAISIE_sim_core_trait_dep.R b/tests/testthat/test-DAISIE_sim_core_trait_dep.R index 1687ef8f..a4c18388 100644 --- a/tests/testthat/test-DAISIE_sim_core_trait_dep.R +++ b/tests/testthat/test-DAISIE_sim_core_trait_dep.R @@ -1,6 +1,6 @@ test_that("nonontogeny oceanic trait_dependnet island should run silent IW", { set.seed(234567890) - expect_silent( + testthat::expect_silent( DAISIE_sim_core_trait_dep( time = 10, mainland_n = 100, @@ -28,7 +28,7 @@ test_that("nonontogeny oceanic trait_dependnet island should run silent IW", { test_that("nonontogeny oceanic trait_dependnet island should run silent CS", { set.seed(420) - expect_silent( + testthat::expect_silent( DAISIE_sim_core_trait_dep( time = 10, mainland_n = 0, @@ -56,7 +56,7 @@ test_that("nonontogeny oceanic trait_dependnet island should run silent CS", { test_that("abuse NULL trait pars", { set.seed(234567890) - expect_error( + testthat::expect_error( DAISIE_sim_core_trait_dep( time = 10, mainland_n = 100, @@ -78,7 +78,7 @@ test_that("abuse NULL trait pars", { }) test_that("abuse NULL trait pars", { set.seed(234567890) - expect_error( + testthat::expect_error( DAISIE_sim_core_trait_dep( time = 10, mainland_n = 100, diff --git a/tests/testthat/test-DAISIE_sim_cr.R b/tests/testthat/test-DAISIE_sim_cr.R index 19c1eb7c..e3f808b5 100644 --- a/tests/testthat/test-DAISIE_sim_cr.R +++ b/tests/testthat/test-DAISIE_sim_cr.R @@ -6,7 +6,7 @@ test_that("A divdepmodel = 'CS' run should produce no output", { clade_carr_cap <- 10.0 imm_rate <- 0.01 ana_rate <- 1.0 - expect_silent( + testthat::expect_silent( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -28,7 +28,7 @@ test_that("A divdepmodel = 'CS' run with cond works as expected", { imm_rate <- 0.01 ana_rate <- 1.0 cond <- 5 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -41,9 +41,7 @@ test_that("A divdepmodel = 'CS' run with cond works as expected", { ) ) - expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) - - + testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) }) @@ -65,7 +63,7 @@ test_that("A divdepmodel = 'CS' run with 2 types and cond > 0 throws warning", { replicates_apply_type2 <- TRUE cond <- 5 - expect_warning( + testthat::expect_warning( sim <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -104,7 +102,7 @@ test_that("A divdepmodel = 'CS' run with cond 0 and cond works as expected", { imm_rate <- 0.01 ana_rate <- 1.0 cond <- 0 - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -117,13 +115,13 @@ test_that("A divdepmodel = 'CS' run with cond 0 and cond works as expected", { ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 5] < 5 ) set.seed(1) # Always run the same sim cond <- 5 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -135,7 +133,7 @@ test_that("A divdepmodel = 'CS' run with cond 0 and cond works as expected", { cond = cond ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 5] >= 5 ) @@ -172,7 +170,7 @@ test_that("A divdepmodel = 'GW' run should produce no output", { imm_rate <- 0.01 ana_rate <- 1.0 num_guilds <- 5 - expect_silent( + testthat::expect_silent( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -203,7 +201,7 @@ test_that("A 2 type with replicates_apply_type2 == TRUE ana_rate_type_2 <- 1.0 prop_type2_pool <- 0.1 replicates_apply_type2 <- TRUE - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -246,7 +244,7 @@ test_that("A 2 type with replicates_apply_type2 == FALSE - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -286,8 +284,8 @@ test_that("output is correct for divdepmodl = 'CS'", { plot_sims = FALSE, verbose = FALSE ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) }) test_that("output is correct for divdepmodel = 'IW'", { @@ -308,8 +306,8 @@ test_that("output is correct for divdepmodel = 'IW'", { plot_sims = FALSE, verbose = FALSE ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) }) test_that("output is correct for divdepmodl = 'GW'", { @@ -331,8 +329,8 @@ test_that("output is correct for divdepmodl = 'GW'", { plot_sims = FALSE, verbose = FALSE ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) }) test_that("Output is silent for nonoceanic_pars[1] != 0 when @@ -345,7 +343,7 @@ test_that("Output is silent for nonoceanic_pars[1] != 0 when imm_rate <- 0.00933207 # immigration rate ana_rate <- 1.010073119 # anagenesis rate nonoceanic_pars <- c(0.1, 0.9) - expect_silent( + testthat::expect_silent( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -381,8 +379,8 @@ test_that("output is correct for nonoceanic_pars[1] != 0 when nonoceanic_pars = nonoceanic_pars, plot_sims = FALSE, verbose = FALSE) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) }) test_that("Output is silent for nonoceanic_pars[1] != 0 when @@ -395,7 +393,7 @@ test_that("Output is silent for nonoceanic_pars[1] != 0 when imm_rate <- 0.00933207 # immigration rate ana_rate <- 1.010073119 # anagenesis rate nonoceanic_pars <- c(0.1, 0.9) - expect_silent( + testthat::expect_silent( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -436,8 +434,8 @@ test_that("output is correct for nonoceanic_pars[1] != 0 when nonoceanic_pars = nonoceanic_pars, plot_sims = FALSE, verbose = FALSE) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) }) test_that("A non-oceanic run should have native species on the island", { @@ -459,9 +457,9 @@ test_that("A non-oceanic run should have native species on the island", { verbose = FALSE ) #number of immigrants (nonendemics) is greater than zero - expect_gt(sim[[1]][[1]]$stt_all[1, 2], 0) + testthat::expect_gt(sim[[1]][[1]]$stt_all[1, 2], 0) #number of anagenetic species (endemic) is greater than zero - expect_gt(sim[[1]][[1]]$stt_all[1, 3], 0) + testthat::expect_gt(sim[[1]][[1]]$stt_all[1, 3], 0) }) test_that("Oceanic and non-oceanic should give same results when @@ -492,7 +490,7 @@ test_that("Oceanic and non-oceanic should give same results when plot_sims = FALSE, verbose = FALSE ) - expect_true(all(names(oceanic_sim) == names(nonoceanic_sim))) + testthat::expect_true(all(names(oceanic_sim) == names(nonoceanic_sim))) }) test_that("abuse: error when mainland n is not multiple of guild number", { @@ -504,7 +502,7 @@ test_that("abuse: error when mainland n is not multiple of guild number", { imm_rate <- 0.00933207 # immigration rate ana_rate <- 1.010073119 # anagenesis rate num_guilds <- 33 - expect_error( + testthat::expect_error( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -519,7 +517,7 @@ test_that("abuse: error when mainland n is not multiple of guild number", { }) test_that("abuse GW parsing errors", { - expect_error() + testthat::expect_error() n_mainland_species <- 100 island_age <- 0.4 clado_rate <- 1.0 @@ -528,7 +526,7 @@ test_that("abuse GW parsing errors", { imm_rate <- 0.01 ana_rate <- 1.0 num_guilds <- "nonsense" - expect_error( + testthat::expect_error( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -546,7 +544,7 @@ test_that("abuse GW parsing errors", { test_that("abuse IW with more than 5 parameters", { n_mainland_species <- 100 island_age <- 0.4 - expect_error( + testthat::expect_error( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -567,7 +565,7 @@ test_that("constant rate oceanic CS prints correct output when replicates <- 1 verbose <- TRUE set.seed(1) - expect_message( + testthat::expect_message( sim <- DAISIE_sim_cr(time = total_time, M = mainland_n, pars = pars, @@ -586,7 +584,7 @@ test_that("constant rate oceanic IW prints correct output when replicates <- 1 verbose <- TRUE set.seed(1) - expect_message( + testthat::expect_message( sim <- DAISIE_sim_cr(time = total_time, M = mainland_n, pars = pars, @@ -615,7 +613,7 @@ test_that("2 type simulation with divdepmodel = 'CS' verbose run should ana_rate_type_2 <- 1.0 prop_type2_pool <- 0.1 replicates_apply_type2 <- FALSE - expect_message( + testthat::expect_message( sim <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -648,7 +646,7 @@ test_that("A divdepmodel = 'GW' run with verbose should print", { imm_rate <- 0.01 ana_rate <- 1.0 num_guilds <- 5 - expect_message( + testthat::expect_message( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -672,7 +670,7 @@ test_that("2 type, no geodynamics, nonoceanic should give error", { set.seed(1) prop_type2_pool <- 0.4 nonoceanic_pars <- c(0.5, 0.5) - expect_error(DAISIE_sim_cr( + testthat::expect_error(DAISIE_sim_cr( time = total_time, M = M, pars = pars, diff --git a/tests/testthat/test-DAISIE_sim_relaxed_rate.R b/tests/testthat/test-DAISIE_sim_relaxed_rate.R index d3eb3382..1042f420 100644 --- a/tests/testthat/test-DAISIE_sim_relaxed_rate.R +++ b/tests/testthat/test-DAISIE_sim_relaxed_rate.R @@ -1,7 +1,7 @@ test_that("A relaxed-cladogenesis should run silent with correct output", { set.seed(1) replicates <- 1 - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -12,21 +12,21 @@ test_that("A relaxed-cladogenesis should run silent with correct output", { verbose = FALSE ) ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) - expect_equal(sim[[1]][[1]]$island_age, 5) - expect_equal(sim[[1]][[1]]$not_present, 97) - expect_true(is.matrix(sim[[1]][[1]]$stt_all)) - expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) - expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) - expect_length(sim[[1]], 4) - expect_equal(sim[[1]][[2]]$branching_times, + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) + testthat::expect_equal(sim[[1]][[1]]$island_age, 5) + testthat::expect_equal(sim[[1]][[1]]$not_present, 97) + testthat::expect_true(is.matrix(sim[[1]][[1]]$stt_all)) + testthat::expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) + testthat::expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) + testthat::expect_length(sim[[1]], 4) + testthat::expect_equal(sim[[1]][[2]]$branching_times, c(5.0000000000000000, 2.0534694381058198, 1.7090490323814100, 1.6624987034718000, 1.5842640341945800, 1.5103422398951900, 0.9381441199311800, 0.8826723461608900, 0.7563448914548900, 0.0135276001879401)) - expect_equal(sim[[1]][[2]]$stac, 2) - expect_equal(sim[[1]][[2]]$missing_species, 0) + testthat::expect_equal(sim[[1]][[2]]$stac, 2) + testthat::expect_equal(sim[[1]][[2]]$missing_species, 0) }) test_that("A relaxed-cladogenesis should cond run silent with correct output", { @@ -34,7 +34,7 @@ test_that("A relaxed-cladogenesis should cond run silent with correct output", { replicates <- 1 pars <- c(5, 1, 10, 0.01, 1, 5) cond <- 5 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -46,7 +46,7 @@ test_that("A relaxed-cladogenesis should cond run silent with correct output", { cond = cond ) ) -expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) +testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) }) test_that("A relaxed-cladogenesis should cond run silent with correct output", { @@ -54,7 +54,7 @@ test_that("A relaxed-cladogenesis should cond run silent with correct output", { replicates <- 1 pars <- c(5, 1, 10, 0.01, 1, 5) cond <- 5 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -67,12 +67,12 @@ test_that("A relaxed-cladogenesis should cond run silent with correct output", { ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 5] >= cond ) set.seed(1) - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -84,7 +84,7 @@ test_that("A relaxed-cladogenesis should cond run silent with correct output", { cond = 0 ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 5] < 5 ) @@ -93,7 +93,7 @@ test_that("A relaxed-cladogenesis should cond run silent with correct output", { test_that("A relaxed-extinction should run silent with correct output", { set.seed(1) replicates <- 1 - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -104,19 +104,19 @@ test_that("A relaxed-extinction should run silent with correct output", { verbose = FALSE ) ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) - expect_equal(sim[[1]][[1]]$island_age, 5) - expect_equal(sim[[1]][[1]]$not_present, 98) - expect_true(is.matrix(sim[[1]][[1]]$stt_all)) - expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) - expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) - expect_length(sim[[1]], 3) - expect_equal(sim[[1]][[2]]$branching_times, + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) + testthat::expect_equal(sim[[1]][[1]]$island_age, 5) + testthat::expect_equal(sim[[1]][[1]]$not_present, 98) + testthat::expect_true(is.matrix(sim[[1]][[1]]$stt_all)) + testthat::expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) + testthat::expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) + testthat::expect_length(sim[[1]], 3) + testthat::expect_equal(sim[[1]][[2]]$branching_times, c(5.0000000000000000, 1.273147361, 0.834710557, 0.503593010, 0.005717738)) - expect_equal(sim[[1]][[2]]$stac, 2) - expect_equal(sim[[1]][[2]]$missing_species, 0) + testthat::expect_equal(sim[[1]][[2]]$stac, 2) + testthat::expect_equal(sim[[1]][[2]]$missing_species, 0) }) test_that("A relaxed-extinction should cond run silent with correct output", { @@ -124,7 +124,7 @@ test_that("A relaxed-extinction should cond run silent with correct output", { replicates <- 1 pars <- c(1, 0.5, 10, 0.01, 1, 1) cond <- 5 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -136,7 +136,7 @@ test_that("A relaxed-extinction should cond run silent with correct output", { cond = cond ) ) - expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) + testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) }) test_that("A relaxed-extinction should cond run silent with correct output", { @@ -144,7 +144,7 @@ test_that("A relaxed-extinction should cond run silent with correct output", { replicates <- 1 pars <- c(1, 0.5, 10, 0.01, 1, 1) cond <- 5 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -157,12 +157,12 @@ test_that("A relaxed-extinction should cond run silent with correct output", { ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 5] >= cond ) set.seed(1) - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -174,7 +174,7 @@ test_that("A relaxed-extinction should cond run silent with correct output", { cond = 0 ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 5] < 5 ) @@ -184,7 +184,7 @@ test_that("A relaxed-extinction should cond run silent with correct output", { test_that("A relaxed-K should run silent with correct output", { set.seed(1) replicates <- 1 - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -195,18 +195,18 @@ test_that("A relaxed-K should run silent with correct output", { verbose = FALSE ) ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) - expect_equal(sim[[1]][[1]]$island_age, 5) - expect_equal(sim[[1]][[1]]$not_present, 99) - expect_true(is.matrix(sim[[1]][[1]]$stt_all)) - expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) - expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) - expect_length(sim[[1]], 2) - expect_equal(sim[[1]][[2]]$branching_times, + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) + testthat::expect_equal(sim[[1]][[1]]$island_age, 5) + testthat::expect_equal(sim[[1]][[1]]$not_present, 99) + testthat::expect_true(is.matrix(sim[[1]][[1]]$stt_all)) + testthat::expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) + testthat::expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) + testthat::expect_length(sim[[1]], 2) + testthat::expect_equal(sim[[1]][[2]]$branching_times, c(5.00000000000000, 2.05346943810582)) - expect_equal(sim[[1]][[2]]$stac, 2) - expect_equal(sim[[1]][[2]]$missing_species, 0) + testthat::expect_equal(sim[[1]][[2]]$stac, 2) + testthat::expect_equal(sim[[1]][[2]]$missing_species, 0) }) test_that("A relaxed-K should cond run silent with correct output", { @@ -214,7 +214,7 @@ test_that("A relaxed-K should cond run silent with correct output", { replicates <- 1 pars <- c(1, 1, 5, 0.01, 1, 5) cond <- 5 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -226,7 +226,7 @@ test_that("A relaxed-K should cond run silent with correct output", { cond = cond ) ) - expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) + testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) }) test_that("A relaxed-K should cond run silent with correct output", { @@ -234,7 +234,7 @@ test_that("A relaxed-K should cond run silent with correct output", { replicates <- 1 pars <- c(1, 1, 5, 0.01, 1, 5) cond <- 5 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -247,12 +247,12 @@ test_that("A relaxed-K should cond run silent with correct output", { ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 5] >= cond ) set.seed(1) - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -264,7 +264,7 @@ test_that("A relaxed-K should cond run silent with correct output", { cond = 0 ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 5] < 5 ) @@ -273,7 +273,7 @@ test_that("A relaxed-K should cond run silent with correct output", { test_that("A relaxed-immigration should run silent with correct output", { set.seed(1) replicates <- 1 - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -284,18 +284,18 @@ test_that("A relaxed-immigration should run silent with correct output", { verbose = FALSE ) ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) - expect_equal(sim[[1]][[1]]$island_age, 5) - expect_equal(sim[[1]][[1]]$not_present, 90) - expect_true(is.matrix(sim[[1]][[1]]$stt_all)) - expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) - expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) - expect_length(sim[[1]], 11) - expect_equal(sim[[1]][[2]]$branching_times, + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) + testthat::expect_equal(sim[[1]][[1]]$island_age, 5) + testthat::expect_equal(sim[[1]][[1]]$not_present, 90) + testthat::expect_true(is.matrix(sim[[1]][[1]]$stt_all)) + testthat::expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) + testthat::expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) + testthat::expect_length(sim[[1]], 11) + testthat::expect_equal(sim[[1]][[2]]$branching_times, c(5.00000000000000, 0.64585619583728)) - expect_equal(sim[[1]][[2]]$stac, 2) - expect_equal(sim[[1]][[2]]$missing_species, 0) + testthat::expect_equal(sim[[1]][[2]]$stac, 2) + testthat::expect_equal(sim[[1]][[2]]$missing_species, 0) }) test_that("A relaxed-immigration should cond run silent with correct output", { @@ -303,7 +303,7 @@ test_that("A relaxed-immigration should cond run silent with correct output", { replicates <- 1 pars <- c(1, 1, 10, 1, 1, 5) cond <- 5 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -315,7 +315,7 @@ test_that("A relaxed-immigration should cond run silent with correct output", { cond = cond ) ) - expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) + testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) }) test_that("A relaxed-immigration should cond run silent with correct output", { @@ -323,7 +323,7 @@ test_that("A relaxed-immigration should cond run silent with correct output", { replicates <- 1 pars <- c(1, 1, 10, 0.01, 1, 0.01) cond <- 5 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -336,12 +336,12 @@ test_that("A relaxed-immigration should cond run silent with correct output", { ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 5] >= cond ) set.seed(3) - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -353,7 +353,7 @@ test_that("A relaxed-immigration should cond run silent with correct output", { cond = 0 ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 5] < 5 ) @@ -362,7 +362,7 @@ test_that("A relaxed-immigration should cond run silent with correct output", { test_that("A relaxed-anagenesis should run silent with correct output", { set.seed(1) replicates <- 1 - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -373,18 +373,18 @@ test_that("A relaxed-anagenesis should run silent with correct output", { verbose = FALSE ) ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) - expect_equal(sim[[1]][[1]]$island_age, 5) - expect_equal(sim[[1]][[1]]$not_present, 98) - expect_true(is.matrix(sim[[1]][[1]]$stt_all)) - expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) - expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) - expect_length(sim[[1]], 3) - expect_equal(sim[[1]][[2]]$branching_times, + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) + testthat::expect_equal(sim[[1]][[1]]$island_age, 5) + testthat::expect_equal(sim[[1]][[1]]$not_present, 98) + testthat::expect_true(is.matrix(sim[[1]][[1]]$stt_all)) + testthat::expect_equal(nrow(sim[[1]][[1]]$stt_all), 26) + testthat::expect_equal(ncol(sim[[1]][[1]]$stt_all), 5) + testthat::expect_length(sim[[1]], 3) + testthat::expect_equal(sim[[1]][[2]]$branching_times, c(5.00000000000000, 2.05346943810582)) - expect_equal(sim[[1]][[2]]$stac, 2) - expect_equal(sim[[1]][[2]]$missing_species, 0) + testthat::expect_equal(sim[[1]][[2]]$stac, 2) + testthat::expect_equal(sim[[1]][[2]]$missing_species, 0) }) test_that("A relaxed-anagenesis should cond run silent with correct output", { @@ -392,7 +392,7 @@ test_that("A relaxed-anagenesis should cond run silent with correct output", { replicates <- 1 pars <- c(1, 1, 10, 0.01, 5, 5) cond <- 5 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -404,7 +404,7 @@ test_that("A relaxed-anagenesis should cond run silent with correct output", { cond = cond ) ) - expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) + testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) }) test_that("A relaxed-anagenesis should cond run silent with correct output", { @@ -412,7 +412,7 @@ test_that("A relaxed-anagenesis should cond run silent with correct output", { replicates <- 1 pars <- c(1, 1, 10, 0.01, 5, 5) cond <- 5 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -425,12 +425,12 @@ test_that("A relaxed-anagenesis should cond run silent with correct output", { ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 5] >= cond ) set.seed(1) - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -442,7 +442,7 @@ test_that("A relaxed-anagenesis should cond run silent with correct output", { cond = 0 ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 5] < 5 ) @@ -451,7 +451,7 @@ test_that("A relaxed-anagenesis should cond run silent with correct output", { test_that("Output is silent and correct for a nonoceanic simulation", { set.seed(1) replicates <- 1 - expect_silent( + testthat::expect_silent( sim <- DAISIE_sim_relaxed_rate( time = 5, M = 100, @@ -463,11 +463,11 @@ test_that("Output is silent and correct for a nonoceanic simulation", { verbose = FALSE ) ) - expect_true(is.list(sim)) - expect_true(length(sim) == replicates) + testthat::expect_true(is.list(sim)) + testthat::expect_true(length(sim) == replicates) #number of immigrants (nonendemics) is greater than zero - expect_gt(sim[[1]][[1]]$stt_all[1, 2], 0) + testthat::expect_gt(sim[[1]][[1]]$stt_all[1, 2], 0) #number of anagenetic species (endemic) is greater than zero - expect_gt(sim[[1]][[1]]$stt_all[1, 3], 0) + testthat::expect_gt(sim[[1]][[1]]$stt_all[1, 3], 0) }) diff --git a/tests/testthat/test-DAISIE_sim_time_dep.R b/tests/testthat/test-DAISIE_sim_time_dep.R index d1dd8dee..aad2fb5b 100644 --- a/tests/testthat/test-DAISIE_sim_time_dep.R +++ b/tests/testthat/test-DAISIE_sim_time_dep.R @@ -18,7 +18,7 @@ test_that("A clean CS ontogeny run should produce no output", { sea_level <- "const" extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - expect_silent( + testthat::expect_silent( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -66,7 +66,7 @@ test_that("use CS split-rates with cond", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) cond <- 5 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -90,7 +90,7 @@ test_that("use CS split-rates with cond", { ) ) - expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) + testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 5] >= cond) }) @@ -116,7 +116,7 @@ test_that("CS split-rates with cond to without", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) cond <- 5 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -139,12 +139,12 @@ test_that("CS split-rates with cond to without", { cond = cond ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 5] >= cond ) set.seed(1) - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -167,7 +167,7 @@ test_that("CS split-rates with cond to without", { cond = 0 ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 5] < cond ) }) @@ -196,7 +196,7 @@ test_that("A clean IW ontogeny run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_silent( + testthat::expect_silent( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -244,7 +244,7 @@ test_that("A clean GW ontogeny run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_silent( + testthat::expect_silent( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -292,7 +292,7 @@ test_that("A clean sea_level run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -341,7 +341,7 @@ test_that("A clean CS ontogeny run with verbose should print to console", { sea_level <- "const" extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - expect_message( + testthat::expect_message( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -387,7 +387,7 @@ test_that("A clean IW ontogeny run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_message( + testthat::expect_message( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -436,7 +436,7 @@ test_that("A clean GW ontogeny run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_message( + testthat::expect_message( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -485,7 +485,7 @@ test_that("A clean GW ontogeny run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_error( + testthat::expect_error( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, diff --git a/tests/testthat/test-DAISIE_sim_trait_dep.R b/tests/testthat/test-DAISIE_sim_trait_dep.R index aeccf4e2..616353f6 100644 --- a/tests/testthat/test-DAISIE_sim_trait_dep.R +++ b/tests/testthat/test-DAISIE_sim_trait_dep.R @@ -17,7 +17,7 @@ test_that("A clean CS two trait simulation run should produce no output", { island_ontogeny <- "const" sea_level <- "const" extcutoff <- 1000 - expect_silent( + testthat::expect_silent( DAISIE_sim_trait_dep( time = island_age, M = n_mainland_species, @@ -54,7 +54,7 @@ test_that("A divdepmodel = 'CS' two trait run with cond works as expected", { island_ontogeny <- "const" sea_level <- "const" extcutoff <- 1000 - expect_silent( + testthat::expect_silent( out <- DAISIE_sim_trait_dep( time = island_age, M = n_mainland_species, @@ -70,7 +70,7 @@ test_that("A divdepmodel = 'CS' two trait run with cond works as expected", { ) ) - expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 8] >= cond) + testthat::expect_true(out[[1]][[1]]$stt_all[nrow(out[[1]][[1]]$stt_all), 8] >= cond) }) test_that("A divdepmodel = 'CS' two trait run cond no cond work as expected", { @@ -94,7 +94,7 @@ test_that("A divdepmodel = 'CS' two trait run cond no cond work as expected", { island_ontogeny <- "const" sea_level <- "const" extcutoff <- 1000 - expect_silent( + testthat::expect_silent( out_cond <- DAISIE_sim_trait_dep( time = island_age, M = n_mainland_species, @@ -110,12 +110,12 @@ test_that("A divdepmodel = 'CS' two trait run cond no cond work as expected", { ) ) - expect_true( + testthat::expect_true( out_cond[[1]][[1]]$stt_all[nrow(out_cond[[1]][[1]]$stt_all), 8] >= cond ) set.seed(1) - expect_silent( + testthat::expect_silent( out_no_cond <- DAISIE_sim_trait_dep( time = island_age, M = n_mainland_species, @@ -131,7 +131,7 @@ test_that("A divdepmodel = 'CS' two trait run cond no cond work as expected", { ) ) - expect_true( + testthat::expect_true( out_no_cond[[1]][[1]]$stt_all[nrow(out_no_cond[[1]][[1]]$stt_all), 8] < 5) }) @@ -155,7 +155,7 @@ test_that("A clean IW two trait simulation run should produce no output", { island_ontogeny <- "const" sea_level <- "const" extcutoff <- 1000 - expect_silent( + testthat::expect_silent( DAISIE_sim_trait_dep( time = island_age, M = n_mainland_species, diff --git a/tests/testthat/test-DAISIE_sumstats_rates.R b/tests/testthat/test-DAISIE_sumstats_rates.R index 6c33c1be..e69b4c2b 100644 --- a/tests/testthat/test-DAISIE_sumstats_rates.R +++ b/tests/testthat/test-DAISIE_sumstats_rates.R @@ -17,5 +17,5 @@ test_that("use simple ontogeny code", { d = 0.2, x = 0.1) ) - expect_true(is.list(out)) + testthat::expect_true(is.list(out)) }) diff --git a/tests/testthat/test-DAISIE_utils.R b/tests/testthat/test-DAISIE_utils.R index f3d90d6d..daa85a48 100644 --- a/tests/testthat/test-DAISIE_utils.R +++ b/tests/testthat/test-DAISIE_utils.R @@ -4,9 +4,9 @@ test_that("sample_relaxed_rate produces correct output for cladogenesis", { set.seed(1) relaxed_pars <- sample_relaxed_rate(pars = pars, relaxed_par = relaxed_par) - expect_true(is.numeric(relaxed_pars)) - expect_length(relaxed_pars, 5) - expect_equal(relaxed_pars, + testthat::expect_true(is.numeric(relaxed_pars)) + testthat::expect_length(relaxed_pars, 5) + testthat::expect_equal(relaxed_pars, c(0.155141356572, 1.0000000, 20.0000000, 0.1000000, 1.0000000)) }) @@ -16,9 +16,9 @@ test_that("sampled_relaxed_rate produces correct output for extinction", { set.seed(1) relaxed_pars <- sample_relaxed_rate(pars = pars, relaxed_par = relaxed_par) - expect_true(is.numeric(relaxed_pars)) - expect_length(relaxed_pars, 5) - expect_equal(relaxed_pars, + testthat::expect_true(is.numeric(relaxed_pars)) + testthat::expect_length(relaxed_pars, 5) + testthat::expect_equal(relaxed_pars, c(1.0000000, 0.155141356572, 20.0000000, 0.1000000, 1.0000000)) }) @@ -28,9 +28,9 @@ test_that("sampled_relaxed_rate produces correct output for carrying capacity", set.seed(1) relaxed_pars <- sample_relaxed_rate(pars = pars, relaxed_par = relaxed_par) - expect_true(is.numeric(relaxed_pars)) - expect_length(relaxed_pars, 5) - expect_equal(relaxed_pars, + testthat::expect_true(is.numeric(relaxed_pars)) + testthat::expect_length(relaxed_pars, 5) + testthat::expect_equal(relaxed_pars, c(1.0000000, 1.0000000, 19.35384340003, 0.1000000, 1.0000000)) }) @@ -40,9 +40,9 @@ test_that("sampled_relaxed_rate produces correct output for immigration", { set.seed(1) relaxed_pars <- sample_relaxed_rate(pars = pars, relaxed_par = relaxed_par) - expect_true(is.numeric(relaxed_pars)) - expect_length(relaxed_pars, 5) - expect_equal(relaxed_pars, + testthat::expect_true(is.numeric(relaxed_pars)) + testthat::expect_length(relaxed_pars, 5) + testthat::expect_equal(relaxed_pars, c(1.0000000, 1.0000000, 20.0000000, 0.155141356572, 1.0000000)) }) @@ -52,14 +52,14 @@ test_that("sampled_relaxed_rate produces correct output for anagenesis", { set.seed(1) relaxed_pars <- sample_relaxed_rate(pars = pars, relaxed_par = relaxed_par) - expect_true(is.numeric(relaxed_pars)) - expect_length(relaxed_pars, 5) - expect_equal(relaxed_pars, + testthat::expect_true(is.numeric(relaxed_pars)) + testthat::expect_length(relaxed_pars, 5) + testthat::expect_equal(relaxed_pars, c(1.0000000, 1.0000000, 20.0000000, 0.1000000, 0.155141356572)) }) test_that("DAISIE_nonoceanic_spec output is silent", { - expect_silent(DAISIE_nonoceanic_spec(prob_samp = 0.5, + testthat::expect_silent(DAISIE_nonoceanic_spec(prob_samp = 0.5, prob_nonend = 0.5, mainland_n = 100)) }) @@ -68,7 +68,7 @@ test_that("DAISIE_nonoceanic_spec output is a list of three vectors", { native_spec <- DAISIE_nonoceanic_spec(prob_samp = 0.1, prob_nonend = 0.9, mainland_n = 1000) - expect_true(class(native_spec) == "list") + testthat::expect_true(class(native_spec) == "list") }) test_that("DAISIE_nonoceanic_spec samples native species @@ -76,15 +76,15 @@ test_that("DAISIE_nonoceanic_spec samples native species native_spec <- DAISIE_nonoceanic_spec(prob_samp = 0.1, prob_nonend = 0.9, mainland_n = 1000) - expect_true(is.list(native_spec)) - expect_true(is.vector(native_spec[[1]])) - expect_true(is.numeric(native_spec[[1]])) - expect_true(is.vector(native_spec[[2]])) - expect_true(is.numeric(native_spec[[2]])) - expect_true(is.vector(native_spec[[3]])) - expect_true(is.numeric(native_spec[[3]])) - expect_gt(length(native_spec[[1]]), 0) - expect_gt(length(native_spec[[2]]), 0) + testthat::expect_true(is.list(native_spec)) + testthat::expect_true(is.vector(native_spec[[1]])) + testthat::expect_true(is.numeric(native_spec[[1]])) + testthat::expect_true(is.vector(native_spec[[2]])) + testthat::expect_true(is.numeric(native_spec[[2]])) + testthat::expect_true(is.vector(native_spec[[3]])) + testthat::expect_true(is.numeric(native_spec[[3]])) + testthat::expect_gt(length(native_spec[[1]]), 0) + testthat::expect_gt(length(native_spec[[2]]), 0) }) test_that("DAISIE_nonoceanic_spec samples no native species @@ -95,9 +95,9 @@ test_that("DAISIE_nonoceanic_spec samples no native species nonoceanic_sample <- DAISIE_nonoceanic_spec(prob_samp = prob_samp, prob_nonend = prob_nonend, mainland_n = mainland_n) - expect_true(nonoceanic_sample$init_nonend_spec == 0) - expect_true(nonoceanic_sample$init_end_spec == 0) - expect_equal(length(nonoceanic_sample$mainland_spec), mainland_n) + testthat::expect_true(nonoceanic_sample$init_nonend_spec == 0) + testthat::expect_true(nonoceanic_sample$init_end_spec == 0) + testthat::expect_equal(length(nonoceanic_sample$mainland_spec), mainland_n) }) test_that("DAISIE_nonoceanic_spec correctly samples number of species @@ -106,19 +106,19 @@ test_that("DAISIE_nonoceanic_spec correctly samples number of species nonoceanic_sample <- DAISIE_nonoceanic_spec(prob_samp = 0.5, prob_nonend = 0.5, mainland_n = 100) - expect_equivalent(nonoceanic_sample$init_nonend_spec_vec, + testthat::expect_equivalent(nonoceanic_sample$init_nonend_spec_vec, c(51, 33, 34, 8, 45, 4, 74, 85, 31, 75, 49, 21, 55, 92, 39, 81, 61, 41, 58, 24, 13, 26, 72, 42)) - expect_equivalent(nonoceanic_sample$init_end_spec_vec, + testthat::expect_equivalent(nonoceanic_sample$init_end_spec_vec, c(80, 5, 44, 3, 12, 25, 40, 17, 84, 1, 22, 79, 99, 16, 9, 78, 83, 14, 50, 18, 64, 20, 70, 69, 53, 28, 67, 93, 73, 7, 95, 30)) - expect_equivalent(nonoceanic_sample$mainland_spec, + testthat::expect_equivalent(nonoceanic_sample$mainland_spec, c(2, 4, 6, 8, 10, 11, 13, 15, 19, 21, 23, 24, 26, 27, 29, 31, 32, 33, 34, @@ -145,7 +145,7 @@ test_that("DAISIE_spec_tables output is silent", { init_end_spec_vec = 31, mainland_spec = c(1:50)) maxspecID <- 50 - expect_silent(DAISIE_spec_tables(stt_table, + testthat::expect_silent(DAISIE_spec_tables(stt_table, total_time, timeval, nonoceanic_sample, @@ -189,49 +189,49 @@ test_that("DAISIE_spec_tables produces correct output", { expected_island_spec[3, ] <- c("15", "15", "0", "I", NA, NA, NA) expected_island_spec[4, ] <- c("25", "25", "0", "I", NA, NA, NA) expected_island_spec[5, ] <- c("51", "31", "0", "A", NA, NA, NA) - expect_true(length(nonoceanic_tables) == 6) - expect_true("stt_table" %in% names(nonoceanic_tables)) - expect_true("init_nonend_spec" %in% names(nonoceanic_tables)) - expect_true("init_end_spec" %in% names(nonoceanic_tables)) - expect_true("mainland_spec" %in% names(nonoceanic_tables)) - expect_true("island_spec" %in% names(nonoceanic_tables)) - expect_equal(nonoceanic_tables$stt_table, expected_stt) - expect_equal(nonoceanic_tables$init_nonend_spec, 4) - expect_equal(nonoceanic_tables$init_end_spec, 1) - expect_equal(nonoceanic_tables$mainland_spec, expected_mainland_spec) - expect_equal(nonoceanic_tables$island_spec, expected_island_spec) + testthat::expect_true(length(nonoceanic_tables) == 6) + testthat::expect_true("stt_table" %in% names(nonoceanic_tables)) + testthat::expect_true("init_nonend_spec" %in% names(nonoceanic_tables)) + testthat::expect_true("init_end_spec" %in% names(nonoceanic_tables)) + testthat::expect_true("mainland_spec" %in% names(nonoceanic_tables)) + testthat::expect_true("island_spec" %in% names(nonoceanic_tables)) + testthat::expect_equal(nonoceanic_tables$stt_table, expected_stt) + testthat::expect_equal(nonoceanic_tables$init_nonend_spec, 4) + testthat::expect_equal(nonoceanic_tables$init_end_spec, 1) + testthat::expect_equal(nonoceanic_tables$mainland_spec, expected_mainland_spec) + testthat::expect_equal(nonoceanic_tables$island_spec, expected_island_spec) }) test_that("translate_island_ontogeny", { - expect_silent(translate_island_ontogeny("const")) - expect_equal(translate_island_ontogeny("const"), 0) - expect_equal(translate_island_ontogeny("beta"), 1) - expect_false(is_island_ontogeny_input("ontogeny")) + testthat::expect_silent(translate_island_ontogeny("const")) + testthat::expect_equal(translate_island_ontogeny("const"), 0) + testthat::expect_equal(translate_island_ontogeny("beta"), 1) + testthat::expect_false(is_island_ontogeny_input("ontogeny")) }) test_that("translate_sea_level", { - expect_silent(translate_sea_level("const")) - expect_equal(translate_sea_level("const"), 0) - expect_equal(translate_sea_level("sine"), 1) - expect_false(is_sea_level_input("sea_level")) + testthat::expect_silent(translate_sea_level("const")) + testthat::expect_equal(translate_sea_level("const"), 0) + testthat::expect_equal(translate_sea_level("sine"), 1) + testthat::expect_false(is_sea_level_input("sea_level")) }) test_that("counstspecies", { utils::data(Galapagos_datalist, package = "DAISIE") - expect_equal(countspecies(Galapagos_datalist[[2]]), 1) - expect_error(countspecies("nonsense")) + testthat::expect_equal(countspecies(Galapagos_datalist[[2]]), 1) + testthat::expect_error(countspecies("nonsense")) }) test_that("counttype1", { utils::data(Galapagos_datalist, package = "DAISIE") - expect_equal(counttype1(Galapagos_datalist[[2]]), TRUE) - expect_error(counttype1("nonsense")) + testthat::expect_equal(counttype1(Galapagos_datalist[[2]]), TRUE) + testthat::expect_error(counttype1("nonsense")) }) test_that("create_CS_version produces correct output", { CS_version <- create_CS_version(model = 1, relaxed_par = NULL) - expect_equal(CS_version, list(model = 1, + testthat::expect_equal(CS_version, list(model = 1, relaxed_par = NULL, par_sd = 0, par_upper_bound = Inf)) @@ -239,13 +239,13 @@ test_that("create_CS_version produces correct output", { relaxed_par = "cladogenesis", par_sd = 10, par_upper_bound = Inf) - expect_equal(CS_version, list(model = 2, + testthat::expect_equal(CS_version, list(model = 2, relaxed_par = "cladogenesis", par_sd = 10, par_upper_bound = Inf)) CS_version <- create_CS_version(model = 3, relaxed_par = NULL) - expect_equal(CS_version, list(model = 3, + testthat::expect_equal(CS_version, list(model = 3, relaxed_par = NULL, par_sd = 0, par_upper_bound = Inf)) @@ -253,9 +253,9 @@ test_that("create_CS_version produces correct output", { }) test_that("abuse create_CS_version", { - expect_error(create_CS_version(model = 4, + testthat::expect_error(create_CS_version(model = 4, relaxed_par = NULL)) - expect_error(create_CS_version(model = 2, + testthat::expect_error(create_CS_version(model = 2, relaxed_par = NULL)) }) diff --git a/tests/testthat/test-are_max_rates_gt_rates.R b/tests/testthat/test-are_max_rates_gt_rates.R index 130217f3..1b347293 100644 --- a/tests/testthat/test-are_max_rates_gt_rates.R +++ b/tests/testthat/test-are_max_rates_gt_rates.R @@ -1,5 +1,5 @@ test_that("basic use", { - expect_true( + testthat::expect_true( are_max_rates_gt_rates( rates = list( immig_rate = 0.1, @@ -15,7 +15,7 @@ test_that("basic use", { ) ) ) - expect_true( + testthat::expect_true( are_max_rates_gt_rates( rates = list( immig_rate = 0.1, @@ -35,7 +35,7 @@ test_that("basic use", { test_that("check returns FALSE when wrong", { - expect_false( + testthat::expect_false( are_max_rates_gt_rates( rates = list( immig_rate = 0.1, @@ -52,7 +52,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_max_rates_gt_rates( rates = list( immig_rate = 0.1, @@ -68,7 +68,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_max_rates_gt_rates( rates = list( immig_rate = 0.1, @@ -85,7 +85,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_max_rates_gt_rates( rates = list( immig_rate = 0.1, @@ -101,7 +101,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_max_rates_gt_rates( rates = list( immig_rate = "nonsense", @@ -117,7 +117,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_max_rates_gt_rates( rates = list( immig_rate = 0.1, diff --git a/tests/testthat/test-are_rates.R b/tests/testthat/test-are_rates.R index 3983b5d5..eec5aaa6 100644 --- a/tests/testthat/test-are_rates.R +++ b/tests/testthat/test-are_rates.R @@ -1,5 +1,5 @@ test_that("basic use", { - expect_true( + testthat::expect_true( are_rates( list( immig_rate = 0.1, @@ -13,7 +13,7 @@ test_that("basic use", { test_that("check returns FALSE when wrong", { - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -23,7 +23,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = "nonsense", @@ -33,7 +33,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( clado_rate = 0.1, @@ -43,7 +43,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -53,7 +53,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( clado_rate = 0.1, @@ -63,7 +63,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -73,7 +73,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -83,7 +83,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -93,7 +93,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -103,7 +103,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = -1, @@ -113,7 +113,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -123,7 +123,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -136,7 +136,7 @@ test_that("check returns FALSE when wrong", { }) test_that("including two trait states", { - expect_true( + testthat::expect_true( are_rates( list( immig_rate = 0.1, @@ -156,7 +156,7 @@ test_that("including two trait states", { test_that("check returns FALSE when wrong", { - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -172,7 +172,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -189,7 +189,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -204,7 +204,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -221,7 +221,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -236,7 +236,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -253,7 +253,7 @@ test_that("check returns FALSE when wrong", { ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -268,7 +268,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -278,7 +278,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -294,7 +294,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -309,7 +309,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -325,7 +325,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -340,7 +340,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -356,7 +356,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -372,7 +372,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -388,7 +388,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -404,7 +404,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -420,7 +420,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -436,7 +436,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, @@ -453,7 +453,7 @@ test_that("check returns FALSE when wrong", { ) ) ) - expect_false( + testthat::expect_false( are_rates( list( immig_rate = 0.1, diff --git a/tests/testthat/test-are_trait_pars.R b/tests/testthat/test-are_trait_pars.R index eae31de1..c8ac543a 100644 --- a/tests/testthat/test-are_trait_pars.R +++ b/tests/testthat/test-are_trait_pars.R @@ -1,5 +1,5 @@ test_that("minimal use", { - expect_true( + testthat::expect_true( are_trait_pars( create_trait_pars( trans_rate = 0.5, diff --git a/tests/testthat/test-create_area_pars.R b/tests/testthat/test-create_area_pars.R index ae52341e..cf9839fd 100644 --- a/tests/testthat/test-create_area_pars.R +++ b/tests/testthat/test-create_area_pars.R @@ -1,5 +1,5 @@ test_that("minimal use", { - expect_silent( + testthat::expect_silent( create_area_pars( max_area = 10, current_area = 5, @@ -28,11 +28,11 @@ test_that("minimal use", { sea_level_frequency = 10, island_gradient_angle = 45 ) - expect_equal(out, reference) + testthat::expect_equal(out, reference) }) test_that("abuse", { - expect_error( + testthat::expect_error( create_area_pars( max_area = 0, current_area = 0, diff --git a/tests/testthat/test-create_trait_pars.R b/tests/testthat/test-create_trait_pars.R index c45f01bc..d7d5e6dc 100644 --- a/tests/testthat/test-create_trait_pars.R +++ b/tests/testthat/test-create_trait_pars.R @@ -1,5 +1,5 @@ test_that("minimal use", { - expect_silent( + testthat::expect_silent( create_trait_pars( trans_rate = 0.5, immig_rate2 = 0.1, @@ -28,6 +28,6 @@ test_that("minimal use", { trans_rate2 = 0.5, M2 = 1000 ) - expect_equal(out, reference) + testthat::expect_equal(out, reference) }) diff --git a/tests/testthat/test-get_ana_rate.R b/tests/testthat/test-get_ana_rate.R index 23dd32d8..453c28d5 100644 --- a/tests/testthat/test-get_ana_rate.R +++ b/tests/testthat/test-get_ana_rate.R @@ -8,5 +8,5 @@ test_that("use", { laa = 1, num_immigrants = 5) expected <- ps_ana_rate * n_immigrants - expect_equal(expected, created) + testthat::expect_equal(expected, created) }) diff --git a/tests/testthat/test-get_clado_rate.R b/tests/testthat/test-get_clado_rate.R index c356f1e0..40175e09 100644 --- a/tests/testthat/test-get_clado_rate.R +++ b/tests/testthat/test-get_clado_rate.R @@ -12,7 +12,7 @@ test_that("use area constant diversity-independent", { A = area ) expected <- ps_clado_rate * n_species * (1 - n_species / carr_cap) - expect_equal(created, expected) + testthat::expect_equal(created, expected) }) test_that("use area constant diversity-dependent", { @@ -29,7 +29,7 @@ test_that("use area constant diversity-dependent", { A = area ) expected <- ps_clado_rate * n_species * (1 - n_species / carr_cap) - expect_equal(created, expected) + testthat::expect_equal(created, expected) }) test_that("use area variable diversity-independent", { @@ -46,7 +46,7 @@ test_that("use area variable diversity-independent", { A = area ) expected <- 1.267914553968891 - expect_equal(created, expected) + testthat::expect_equal(created, expected) }) test_that("use area variable diversity-dependent", { @@ -63,5 +63,5 @@ test_that("use area variable diversity-dependent", { A = area ) expected <- 1.211562796014718 - expect_equal(created, expected) + testthat::expect_equal(created, expected) }) diff --git a/tests/testthat/test-get_ext_rate.R b/tests/testthat/test-get_ext_rate.R index 66ed0042..7167df6b 100644 --- a/tests/testthat/test-get_ext_rate.R +++ b/tests/testthat/test-get_ext_rate.R @@ -11,7 +11,7 @@ test_that("use area constant", { A = area) expected <- ps_ext_rate * n_species - expect_equal(created, expected) + testthat::expect_equal(created, expected) }) test_that("use area variable", { @@ -26,5 +26,5 @@ test_that("use area variable", { num_spec = n_species, A = area) expected <- 6.354625877794252 - expect_equal(created, expected) + testthat::expect_equal(created, expected) }) diff --git a/tests/testthat/test-get_immig_rate.R b/tests/testthat/test-get_immig_rate.R index 51fbeda3..062b28d0 100644 --- a/tests/testthat/test-get_immig_rate.R +++ b/tests/testthat/test-get_immig_rate.R @@ -14,7 +14,7 @@ test_that("use area constant diversity-independent", { expected <- ps_imm_rate * n_mainland_species * (1 - n_island_species / carr_cap) - expect_equal(expected, created) + testthat::expect_equal(expected, created) }) test_that("use area constant diversity-dependent", { @@ -33,7 +33,7 @@ test_that("use area constant diversity-dependent", { expected <- ps_imm_rate * n_mainland_species * (1 - n_island_species / carr_cap) - expect_equal(expected, created) + testthat::expect_equal(expected, created) }) test_that("use area variable (ontogeny) diversity-dependent", { @@ -50,5 +50,5 @@ test_that("use area variable (ontogeny) diversity-dependent", { K = carr_cap, mainland_n = n_mainland_species) expected <- 0.095 - expect_equal(expected, created) + testthat::expect_equal(expected, created) }) diff --git a/tests/testthat/test-is_island_ontogeny_input.R b/tests/testthat/test-is_island_ontogeny_input.R index 907aac71..f06584c1 100644 --- a/tests/testthat/test-is_island_ontogeny_input.R +++ b/tests/testthat/test-is_island_ontogeny_input.R @@ -1,20 +1,20 @@ test_that("Returns TRUE when correct", { - expect_true( + testthat::expect_true( is_island_ontogeny_input(island_ontogeny = "const") ) - expect_true( + testthat::expect_true( is_island_ontogeny_input(island_ontogeny = "beta") ) }) test_that("Returns FALSE when not string", { - expect_false( + testthat::expect_false( is_island_ontogeny_input(island_ontogeny = 2) ) }) test_that("Returns FALSE when wrong string", { - expect_false( + testthat::expect_false( is_island_ontogeny_input(island_ontogeny = "nonsense") ) }) diff --git a/tests/testthat/test-is_sea_level_input.R b/tests/testthat/test-is_sea_level_input.R index 04fc5887..a9975359 100644 --- a/tests/testthat/test-is_sea_level_input.R +++ b/tests/testthat/test-is_sea_level_input.R @@ -1,20 +1,20 @@ test_that("Returns TRUE when correct", { - expect_true( + testthat::expect_true( is_sea_level_input(sea_level = "const") ) - expect_true( + testthat::expect_true( is_sea_level_input(sea_level = "sine") ) }) test_that("Returns FALSE when not string", { - expect_false( + testthat::expect_false( is_sea_level_input(sea_level = 2) ) }) test_that("Returns FALSE when wrong string", { - expect_false( + testthat::expect_false( is_sea_level_input(sea_level = "nonsense") ) }) diff --git a/tests/testthat/test-is_simulation_outputs.R b/tests/testthat/test-is_simulation_outputs.R index 79177c02..927ecae4 100644 --- a/tests/testthat/test-is_simulation_outputs.R +++ b/tests/testthat/test-is_simulation_outputs.R @@ -1,6 +1,6 @@ test_that("use", { - expect_false(is_simulation_outputs("nonsense")) - expect_true(is_simulation_outputs(DAISIE_sim_cr( + testthat::expect_false(is_simulation_outputs("nonsense")) + testthat::expect_true(is_simulation_outputs(DAISIE_sim_cr( time = 0.4, M = 10, pars = c(2, 2, Inf, 0.001, 1), @@ -8,7 +8,7 @@ test_that("use", { plot_sims = FALSE, verbose = FALSE))) - expect_true(is_simulation_outputs(DAISIE_sim_time_dep( + testthat::expect_true(is_simulation_outputs(DAISIE_sim_time_dep( time = 2, M = 500, pars = c(0.00001, 1, 0.05, 0.001, 1), @@ -42,7 +42,7 @@ test_that("abuse is simulation outputs", { verbose = FALSE ) names(output[[1]][[1]])[2] <- "nonsense" - expect_false(is_simulation_outputs(output)) + testthat::expect_false(is_simulation_outputs(output)) }) test_that("abuse is simulation outputs", { @@ -56,5 +56,5 @@ test_that("abuse is simulation outputs", { verbose = FALSE ) names(output[[1]][[1]])[3] <- "nonsense" - expect_false(is_simulation_outputs(output)) + testthat::expect_false(is_simulation_outputs(output)) }) diff --git a/tests/testthat/test-island_area.R b/tests/testthat/test-island_area.R index 9d02ee77..f73b65ec 100644 --- a/tests/testthat/test-island_area.R +++ b/tests/testthat/test-island_area.R @@ -12,7 +12,7 @@ test_that("is valid island area with constant area", { island_ontogeny = translate_island_ontogeny("const"), sea_level = translate_sea_level("const") ) - expect_true(is.numeric(area) && area >= 0) + testthat::expect_true(is.numeric(area) && area >= 0) }) test_that("is valid island area with ontogeny", { @@ -34,7 +34,7 @@ test_that("is valid island area with ontogeny", { island_ontogeny = translate_island_ontogeny("beta"), sea_level = translate_sea_level("const") ) - expect_true(is.numeric(area) && area >= 0) + testthat::expect_true(is.numeric(area) && area >= 0) }) test_that("is valid island area with sea level", { @@ -51,7 +51,7 @@ test_that("is valid island area with sea level", { island_ontogeny = translate_island_ontogeny("const"), sea_level = translate_sea_level("sine") ) - expect_true(is.numeric(area) && area >= 0) + testthat::expect_true(is.numeric(area) && area >= 0) }) test_that("is valid island area with ontogeny and sea level", { @@ -72,11 +72,11 @@ test_that("is valid island area with ontogeny and sea level", { island_ontogeny = translate_island_ontogeny("beta"), sea_level = translate_sea_level("sine") ) - expect_true(is.numeric(area) && area >= 0) + testthat::expect_true(is.numeric(area) && area >= 0) }) test_that("abuse island area with constant area", { - expect_warning(island_area(timeval = 2, + testthat::expect_warning(island_area(timeval = 2, total_time = 5, area_pars = create_area_pars( max_area = 10, diff --git a/tests/testthat/test-odeint.R b/tests/testthat/test-odeint.R index 8fae2a5d..77aa5698 100644 --- a/tests/testthat/test-odeint.R +++ b/tests/testthat/test-odeint.R @@ -33,7 +33,7 @@ test_that("odeint solvers give the same result as deSolve solvers", { loglik_rkd5 <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) methode <- 'odeint::bulirsch_stoer' loglik_bs <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) - testthat:: expect_equal(loglik_lsodes, loglik_rkck54) + testthat::expect_equal(loglik_lsodes, loglik_rkck54) testthat::expect_equal(loglik_lsodes, loglik_rkf78) testthat::expect_equal(loglik_lsodes, loglik_rkd5) testthat::expect_equal(loglik_lsodes, loglik_bs) diff --git a/tests/testthat/test-printing.R b/tests/testthat/test-printing.R index 30fac8de..0992a3b0 100644 --- a/tests/testthat/test-printing.R +++ b/tests/testthat/test-printing.R @@ -1,5 +1,5 @@ test_that("print_parameters_and_loglik works", { - expect_message( + testthat::expect_message( print_parameters_and_loglik( pars = c(1, 2:6), loglik = -3, @@ -7,20 +7,20 @@ test_that("print_parameters_and_loglik works", { type = 'clade_loglik' ), regexp = "Status of colonist: 1, Parameters: 2.000000, 3.000000, 4.000000, 5.000000, 6.000000, Loglikelihood: -3.000000") - expect_message(print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = 3, type = 'island_loglik')) + testthat::expect_message(print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = 3, type = 'island_loglik')) - expect_message(print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = 3, type = 'island_ML')) - expect_message(print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = 3, type = 'global_ML', distance_dep = 'power')) - expect_message(print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = 3, type = 'global_ML', distance_dep = 'sigmoidal_col')) - expect_message(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 3, type = 'multiple_island_ML')) + testthat::expect_message(print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = 3, type = 'island_ML')) + testthat::expect_message(print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = 3, type = 'global_ML', distance_dep = 'power')) + testthat::expect_message(print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = 3, type = 'global_ML', distance_dep = 'sigmoidal_col')) + testthat::expect_message(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 3, type = 'multiple_island_ML')) - expect_silent(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 1, type = 'multiple_island_ML')) - expect_silent(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 0, type = 'multiple_island_ML')) + testthat::expect_silent(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 1, type = 'multiple_island_ML')) + testthat::expect_silent(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 0, type = 'multiple_island_ML')) }) test_that("print_ml_par_settings works", { - expect_message( + testthat::expect_message( print_ml_par_settings( namepars = letters[1:5], idparsopt = 1:5, @@ -32,7 +32,7 @@ test_that("print_ml_par_settings works", { regexp = "You are optimizing: a b c d e You are fixing: nothing") - expect_message( + testthat::expect_message( print_ml_par_settings( namepars = letters[1:5], idparsopt = 1:4, @@ -44,7 +44,7 @@ You are fixing: nothing") regexp = "You are optimizing: a b c d You are fixing: e") - expect_message( + testthat::expect_message( print_ml_par_settings( namepars = letters[1:5], idparsopt = 1:5, @@ -57,7 +57,7 @@ You are fixing: e") You are fixing: nothing You are not shifting: a b c d") - expect_silent( + testthat::expect_silent( print_ml_par_settings( namepars = letters[1:5], idparsopt = 1:5, @@ -71,7 +71,7 @@ You are not shifting: a b c d") }) test_that("print_init_ll works", { - expect_message( + testthat::expect_message( print_init_ll( initloglik = 10, verbose = 1 @@ -80,7 +80,7 @@ test_that("print_init_ll works", { The loglikelihood for the initial parameter values is 10 Optimizing the likelihood - this may take a while.") - expect_silent( + testthat::expect_silent( print_init_ll( initloglik = 10, verbose = 0 diff --git a/tests/testthat/test-rosenbrock_abm1_steppers.R b/tests/testthat/test-rosenbrock_abm1_steppers.R index 6037871c..5d680880 100644 --- a/tests/testthat/test-rosenbrock_abm1_steppers.R +++ b/tests/testthat/test-rosenbrock_abm1_steppers.R @@ -23,6 +23,6 @@ test_that("rosenbrock4 and adams bashforth moulton1 work", { DAISIE_CS_max_steps(100000000) DAISIE_abm_factor(0.000001) loglik_abm <- DAISIE_loglik_all(pars1, pars2, Galapagos_datalist_2types, methode = methode) - expect_equal(loglik_lsodes, loglik_rb) - expect_equal(loglik_lsodes, loglik_abm, tol = 1E-6) + testthat::expect_equal(loglik_lsodes, loglik_rb) + testthat::expect_equal(loglik_lsodes, loglik_abm, tol = 1E-6) }) diff --git a/tests/testthat/test-time_dep_vs_cr.R b/tests/testthat/test-time_dep_vs_cr.R index 8751739f..df6fd43a 100644 --- a/tests/testthat/test-time_dep_vs_cr.R +++ b/tests/testthat/test-time_dep_vs_cr.R @@ -59,13 +59,13 @@ test_that("constant rate output matches time dependent code", { peak = 1 ) - expect_equal( + testthat::expect_equal( time_dep_out[[1]][2, ], cr_out[[1]][[1]]$stt_all[2, 1:4] ) # Following lines will necessarily be different, see note. - expect_true( + testthat::expect_true( !all(time_dep_out[[1]][3, ] == cr_out[[1]][[1]]$stt_all[3, 1:4]) ) diff --git a/tests/testthat/test-update_max_rates.R b/tests/testthat/test-update_max_rates.R index 6f33bb53..b4a3142b 100644 --- a/tests/testthat/test-update_max_rates.R +++ b/tests/testthat/test-update_max_rates.R @@ -34,7 +34,7 @@ test_that("update_max_rates constant rates is silent and gives correct output", island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(42) - expect_silent(rates <- update_max_rates( + testthat::expect_silent(rates <- update_max_rates( gam = gam, laa = laa, lac = lac, @@ -47,14 +47,14 @@ test_that("update_max_rates constant rates is silent and gives correct output", mainland_n = mainland_n, Amin = Amin, Amax = Amax)) - expect_true(are_max_rates(rates)) + testthat::expect_true(are_max_rates(rates)) expected_rates <- list( ext_max_rate = 0, immig_max_rate = 0.009, ana_max_rate = 0, clado_max_rate = 0 ) - expect_equal(rates, expected_rates) + testthat::expect_equal(rates, expected_rates) }) @@ -82,7 +82,7 @@ test_that("update area-dependent max rates is silent and gives correct output", island_ontogeny = 1, sea_level = 0) - expect_silent(rates <- update_max_rates( + testthat::expect_silent(rates <- update_max_rates( gam = 0.009, laa = 1.0, lac = 2.5, @@ -95,14 +95,14 @@ test_that("update area-dependent max rates is silent and gives correct output", mainland_n = 1, Amin = Amin, Amax = Amax)) - expect_true(are_max_rates(rates)) + testthat::expect_true(are_max_rates(rates)) expected_rates <- list( ext_max_rate = 0, immig_max_rate = 0.009, ana_max_rate = 0, clado_max_rate = 0 ) - expect_equal(rates, expected_rates) + testthat::expect_equal(rates, expected_rates) }) #test_that("update area-dependent rates with sea-level is silent and gives diff --git a/tests/testthat/test-update_rates.R b/tests/testthat/test-update_rates.R index 4a0479b4..7021449b 100644 --- a/tests/testthat/test-update_rates.R +++ b/tests/testthat/test-update_rates.R @@ -21,7 +21,7 @@ test_that("update_rates constant rates is silent and gives correct output", { num_immigrants <- 0 mainland_n <- 1 set.seed(42) - expect_silent(rates <- update_rates( + testthat::expect_silent(rates <- update_rates( timeval = timeval, total_time = total_time, gam = gam, @@ -37,12 +37,12 @@ test_that("update_rates constant rates is silent and gives correct output", { num_spec = num_spec, num_immigrants = num_immigrants, mainland_n = mainland_n)) - expect_true(are_rates(rates)) + testthat::expect_true(are_rates(rates)) expected_rates <- list(immig_rate = 0.009, ext_rate = 0, ana_rate = 0, clado_rate = 0) - expect_equal(rates, expected_rates) + testthat::expect_equal(rates, expected_rates) }) @@ -63,7 +63,7 @@ test_that("update area-dependent rates is silent and gives correct output", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) peak <- calc_peak(total_time = 1, area_pars = area_pars) - expect_silent(rates <- update_rates( + testthat::expect_silent(rates <- update_rates( timeval = 0, total_time = 1, gam = gam, @@ -80,12 +80,12 @@ test_that("update area-dependent rates is silent and gives correct output", { num_immigrants = 0, mainland_n = 1, peak = peak)) - expect_true(are_rates(rates)) + testthat::expect_true(are_rates(rates)) expected_rates <- list(immig_rate = 0, ext_rate = 0, ana_rate = 0, clado_rate = 0) - expect_equal(rates, expected_rates) + testthat::expect_equal(rates, expected_rates) }) #test_that("update area-dependent rates with sea-level is silent and gives From ec1ef3ceeccf5ee179f599c102a7bbed5f0c0d8e Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 12:51:00 +0200 Subject: [PATCH 58/70] [run ci] --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5e76e686..0be8e109 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction Version: 4.4.1 -Date: 2023-10-07 +Date: 2023-10-08 Depends: R (>= 4.2.0) biocViews: Imports: From 03a3c12075efc4281bf5985f73ca1a33abe2990c Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 13:48:14 +0200 Subject: [PATCH 59/70] Add tolerance in test [run ci] --- tests/testthat/test-integration_DAISIE.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 8e07a601..d68d1f09 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -165,7 +165,7 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence verbose = 0 ) - testthat::expect_equal(expected_mle, tested_mle, tol = 1E-3) + testthat::expect_equal(expected_mle, tested_mle) # Results match if prob_init_pres is removed testthat::expect_equal(expected_calculated_mle, tested_mle[-6]) }) @@ -208,7 +208,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial ## revert output back to the console -- only then access the file! # sink(type = "message") # sink() - testthat::expect_equal(expected_mle, tested_mle) + testthat::expect_equal(expected_mle, tested_mle, tol = 3E-4) }) From 6c31f6842b2801eca9f68eabcdcafbd88cf644ff Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sun, 8 Oct 2023 20:30:16 +0200 Subject: [PATCH 60/70] Skip test [run ci] --- tests/testthat/test-integration_DAISIE.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index d68d1f09..d5c11386 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -172,6 +172,7 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence test_that("DAISIE_ML simple case works with nonzero probability of initial presence", { + skip("TODO: FIX DIFFERENT OUTPUT DEPENDING ON OS @03a3c12075efc4281bf5985f73ca1a33abe2990c") skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), message = "Run only on CI") expected_mle <- data.frame( From 373e46308afead6c9d836188a2038f0ac4d46674 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sun, 8 Oct 2023 20:31:01 +0200 Subject: [PATCH 61/70] Increment version number to 4.4.2 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0be8e109..d2648f58 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction -Version: 4.4.1 +Version: 4.4.2 Date: 2023-10-08 Depends: R (>= 4.2.0) biocViews: diff --git a/NEWS.md b/NEWS.md index bc057db3..ef90c49d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# DAISIE 4.4.2 + # DAISIE 4.4.0 * No longer include patched version of `boost/numeric/odeint/stepper/bulirsch_stoer.hpp`, From f16182395e29b3395e7cfdf5bc85a9f38281e906 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Sun, 8 Oct 2023 20:34:28 +0200 Subject: [PATCH 62/70] Should be version 4.4.1, not 4.4.2 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d2648f58..0be8e109 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction -Version: 4.4.2 +Version: 4.4.1 Date: 2023-10-08 Depends: R (>= 4.2.0) biocViews: From f272fbeeda5f0f26f70fc55526651d01c23c898e Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 21:15:40 +0200 Subject: [PATCH 63/70] Set tolerance a bit higher [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index d5c11386..204d74d1 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -209,7 +209,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial ## revert output back to the console -- only then access the file! # sink(type = "message") # sink() - testthat::expect_equal(expected_mle, tested_mle, tol = 3E-4) + testthat::expect_equal(expected_mle, tested_mle, tol = 5E-4) }) From e5496e05dfc9fa0e82335f59de73295b823782cd Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 21:21:49 +0200 Subject: [PATCH 64/70] Skip test --- tests/testthat/test-integration_DAISIE.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index 204d74d1..a670d049 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -209,7 +209,8 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial ## revert output back to the console -- only then access the file! # sink(type = "message") # sink() - testthat::expect_equal(expected_mle, tested_mle, tol = 5E-4) + testthat::expect_equal(expected_mle, tested_mle) + #tol = 5E-4 will avoid the errors on ubuntu/mac }) From ca7cbb216388a8e5d89cfd835cb7a3c8f6a55364 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Sun, 8 Oct 2023 21:23:17 +0200 Subject: [PATCH 65/70] skip test [run ci] --- tests/testthat/test-integration_DAISIE.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index a670d049..d72b40ff 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -210,7 +210,7 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial # sink(type = "message") # sink() testthat::expect_equal(expected_mle, tested_mle) - #tol = 5E-4 will avoid the errors on ubuntu/mac + #tol = 5E-4 will avoid the errors on ubuntu/mac while ok on Windows }) From f2165cf1f11d589e73b54a10faf1afe2fa99734f Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 10 Oct 2023 16:25:14 +0200 Subject: [PATCH 66/70] Add pkgdown --- .Rbuildignore | 3 +++ .gitignore | 1 + _pkgdown.yml | 4 ++++ 3 files changed, 8 insertions(+) create mode 100644 _pkgdown.yml diff --git a/.Rbuildignore b/.Rbuildignore index 6aaa3e6d..a95362f4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -19,3 +19,6 @@ ^\.vscode$ ^dummy\.R ^LICENSE\.md$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.gitignore b/.gitignore index 57d068ce..9d1adf61 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ src/*.gcno **/.DS_Store **/Rplots.pdf Meta +docs diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 00000000..d71acfb9 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: ~ +template: + bootstrap: 5 + From 470b005bb6ae995c3a9a73515e76e880f99e3d1e Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 10 Oct 2023 16:25:19 +0200 Subject: [PATCH 67/70] Update NEWS.md --- NEWS.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index ef90c49d..0a5047c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,11 @@ -# DAISIE 4.4.2 +# DAISIE 4.4.1 + +* Fix bug in the calculation of shift loglikelihoods. +* Fix bug where parameters being optimized could incorrectly be `Inf` #159 #160 (@joshwlambert). +* `DAISIE_SR_loglik_CS_M1()` is now `DAISIE_loglik_CS_shift()`. +* New pkgdown website. +* Several improvements to the relaxed rate code. + # DAISIE 4.4.0 From 9b7dbfc3cbb91380fa5643f7615ade81ab798817 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Tue, 10 Oct 2023 17:38:45 +0200 Subject: [PATCH 68/70] Update with page url --- .github/workflows/pkgdown.yaml | 48 ++++++++++++++++++++++++++++++++++ DESCRIPTION | 3 ++- _pkgdown.yml | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pkgdown.yaml diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 00000000..ed7650c7 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/DESCRIPTION b/DESCRIPTION index 0be8e109..fc26cacc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -114,6 +114,7 @@ NeedsCompilation: yes SystemRequirements: C++17 Encoding: UTF-8 VignetteBuilder: knitr -URL: https://github.com/rsetienne/DAISIE +URL: https://github.com/rsetienne/DAISIE, + https://rsetienne.github.io/DAISIE/ BugReports: https://github.com/rsetienne/DAISIE/issues RoxygenNote: 7.2.3 diff --git a/_pkgdown.yml b/_pkgdown.yml index d71acfb9..dcfda1fe 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,4 @@ -url: ~ +url: https://rsetienne.github.io/DAISIE/ template: bootstrap: 5 From 35cad4c3a7ae789e213032ed76cef79bba0b8e9a Mon Sep 17 00:00:00 2001 From: Neves-P Date: Fri, 20 Oct 2023 17:43:15 +0200 Subject: [PATCH 69/70] Add tolerance again [run ci] --- tests/testthat/test-integration_DAISIE.R | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index d72b40ff..857af43a 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -172,7 +172,6 @@ test_that("DAISIE_ML simple case works with zero probability of initial presence test_that("DAISIE_ML simple case works with nonzero probability of initial presence", { - skip("TODO: FIX DIFFERENT OUTPUT DEPENDING ON OS @03a3c12075efc4281bf5985f73ca1a33abe2990c") skip_if(Sys.getenv("CI") == "" && !(Sys.getenv("USERNAME") == "rampa"), message = "Run only on CI") expected_mle <- data.frame( @@ -188,12 +187,6 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial ) utils::data(Galapagos_datalist) - ## capture all the output to a file. - # zz <- file("all.Rout", open = "wt") - # sink(zz) - # sink(zz, type = "message") - - # try( tested_mle <- DAISIE_ML( datalist = Galapagos_datalist, initparsopt = c(2.5, 2.7, 20, 0.009, 1.01), @@ -204,13 +197,9 @@ test_that("DAISIE_ML simple case works with nonzero probability of initial verbose = 0 # verbose = 3, ) - # ) - - ## revert output back to the console -- only then access the file! - # sink(type = "message") - # sink() - testthat::expect_equal(expected_mle, tested_mle) - #tol = 5E-4 will avoid the errors on ubuntu/mac while ok on Windows + testthat::expect_equal(expected_mle, tested_mle, tolerance = 2E-3) + # tolerance due to different OS results between windows, macOS and + # ubuntu added in #162 }) From b0d29f29c1a358e2ed7225949c1bf7961d0080c6 Mon Sep 17 00:00:00 2001 From: Pedro Santos Neves <10762799+Neves-P@users.noreply.github.com> Date: Fri, 20 Oct 2023 18:34:37 +0200 Subject: [PATCH 70/70] Update date --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fc26cacc..de450254 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction Version: 4.4.1 -Date: 2023-10-08 +Date: 2023-10-20 Depends: R (>= 4.2.0) biocViews: Imports: