From 4ccd34c8999ec35f17c80de3f0cde9b2dded1ae5 Mon Sep 17 00:00:00 2001 From: AugustT Date: Mon, 10 Feb 2020 14:24:26 +0000 Subject: [PATCH] Updates to address the archiving of SDMTools. This packaged is moved to suggests, tests that use it are skipped if it is not installed --- DESCRIPTION | 8 +- NAMESPACE | 2 - R/test_outputs.R | 215 ++++++++++++---------- tests/testthat/testChangeWorkflow.R | 83 +++++---- tests/testthat/testcall_path.R | 3 + tests/testthat/testsummary.zoonWorkflow.R | 3 + tests/testthat/testtestModule.R | 24 ++- zoon_package.Rproj | 3 +- 8 files changed, 184 insertions(+), 157 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cfea3d7..3bd2678 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: zoon Type: Package Title: Reproducible, Accessible & Shareable Species Distribution Modelling -Version: 0.6.4 -Date: 2019-11-13 +Version: 0.6.5 +Date: 2012-02-10 Authors@R: c(person("Tom", "August", role = c("aut", "cre"), email = "tomaug@ceh.ac.uk"), person("Tim", "Lucas", role = "aut", comment = c(ORCID = "0000-0003-4694-8107")), @@ -24,7 +24,6 @@ Imports: rgdal, roxygen2, rworldmap, - SDMTools, sp, testthat Depends: @@ -32,7 +31,8 @@ Depends: R (>= 3.2.0) Suggests: knitr, - maxlike + maxlike, + SDMTools VignetteBuilder: knitr LazyData: TRUE URL: https://github.com/zoonproject/zoon diff --git a/NAMESPACE b/NAMESPACE index 41f6ecf..f2f7774 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -45,8 +45,6 @@ import(sp) import(testthat) importFrom(RCurl,getURL) importFrom(RCurl,url.exists) -importFrom(SDMTools,auc) -importFrom(SDMTools,confusion.matrix) importFrom(grDevices,dev.off) importFrom(grDevices,grey) importFrom(grDevices,png) diff --git a/R/test_outputs.R b/R/test_outputs.R index ac0c9a7..413fb7d 100644 --- a/R/test_outputs.R +++ b/R/test_outputs.R @@ -1,4 +1,3 @@ -#' @importFrom SDMTools auc confusion.matrix #' @import randomForest #' # A function for testing the outputs conform to the expected @@ -171,36 +170,38 @@ test_occurrence_outputs <- function (roxy_parse, modulePath, en) { "when chained in a workflow") ) - - # test list + crossvalidation - w <- tryCatchWorkflow( - expr = { - w <- workflow( - occurrence = list( - OccurrenceModule, - OccurrenceModule - ), - covariate = NaiveRandomRaster( - extent = myExtent, - res = 0.5, - seed = 123 - ), - process = BackgroundAndCrossvalid, - model = LogisticRegression, - output = PerformanceMeasures, - forceReproducible = FALSE - ) - }, - placeholder = "OccurrenceModule", - fun = roxy_parse$name - ) - if (inherits(w, what = "moduleError")) stop(w) - - expect_is( - w, "zoonWorkflow", - info = paste("The occurrence module did not work", - "when listed in a workflow with crossvalidation") - ) + SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE) + if(SDMtools_check){ + # test list + crossvalidation + w <- tryCatchWorkflow( + expr = { + w <- workflow( + occurrence = list( + OccurrenceModule, + OccurrenceModule + ), + covariate = NaiveRandomRaster( + extent = myExtent, + res = 0.5, + seed = 123 + ), + process = BackgroundAndCrossvalid, + model = LogisticRegression, + output = PerformanceMeasures, + forceReproducible = FALSE + ) + }, + placeholder = "OccurrenceModule", + fun = roxy_parse$name + ) + if (inherits(w, what = "moduleError")) stop(w) + + expect_is( + w, "zoonWorkflow", + info = paste("The occurrence module did not work", + "when listed in a workflow with crossvalidation") + ) + } } else if (data_type == "presence/absence") { # test normal @@ -259,35 +260,39 @@ test_occurrence_outputs <- function (roxy_parse, modulePath, en) { "when chained in a workflow") ) - # test list + crossvalidation - w <- tryCatchWorkflow( - expr = { - w <- workflow( - occurrence = list( - OccurrenceModule, - OccurrenceModule - ), - covariate = NaiveRandomRaster( - extent = myExtent, - res = 0.5, - seed = 123 - ), - process = Crossvalidate, - model = LogisticRegression, - output = PerformanceMeasures, - forceReproducible = FALSE - ) - }, - placeholder = "OccurrenceModule", - fun = roxy_parse$name - ) - if (inherits(w, what = "moduleError")) stop(w) - - expect_is( - w, "zoonWorkflow", - info = paste("The occurrence module did not work", - "when listed in a workflow with crossvalidation") - ) + SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE) + if(SDMtools_check){ + + # test list + crossvalidation + w <- tryCatchWorkflow( + expr = { + w <- workflow( + occurrence = list( + OccurrenceModule, + OccurrenceModule + ), + covariate = NaiveRandomRaster( + extent = myExtent, + res = 0.5, + seed = 123 + ), + process = Crossvalidate, + model = LogisticRegression, + output = PerformanceMeasures, + forceReproducible = FALSE + ) + }, + placeholder = "OccurrenceModule", + fun = roxy_parse$name + ) + if (inherits(w, what = "moduleError")) stop(w) + + expect_is( + w, "zoonWorkflow", + info = paste("The occurrence module did not work", + "when listed in a workflow with crossvalidation") + ) + } } ## Add tests for proportion and abundance ## } } @@ -987,28 +992,32 @@ test_model_outputs <- function (roxy_parse, modulePath, en) { info = "The model module did not work in a list workflow" ) - # crossvalidate - w <- tryCatchWorkflow( - expr = { - w <- workflow( - occurrence = NaiveRandomPresenceAbsence(n = 1000, - seed = 123), - covariate = NaiveRandomRaster, - process = Crossvalidate, - model = list(ModelModule, ModelModule), - output = PerformanceMeasures, - forceReproducible = FALSE - ) - }, - placeholder = "ModelModule", - fun = roxy_parse$name - ) - if (inherits(w, what = "moduleError")) stop(w) + SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE) + if(SDMtools_check){ - expect_is( - w, "zoonWorkflow", - info = paste("The process module did not work in a", - "crossvalidation workflow")) + # crossvalidate + w <- tryCatchWorkflow( + expr = { + w <- workflow( + occurrence = NaiveRandomPresenceAbsence(n = 1000, + seed = 123), + covariate = NaiveRandomRaster, + process = Crossvalidate, + model = list(ModelModule, ModelModule), + output = PerformanceMeasures, + forceReproducible = FALSE + ) + }, + placeholder = "ModelModule", + fun = roxy_parse$name + ) + if (inherits(w, what = "moduleError")) stop(w) + + expect_is( + w, "zoonWorkflow", + info = paste("The process module did not work in a", + "crossvalidation workflow")) + } } else if (data_type == "presence/background") { @@ -1081,26 +1090,30 @@ test_model_outputs <- function (roxy_parse, modulePath, en) { info = "The model module did not work in a list workflow" ) - # crossvalidate - w <- tryCatchWorkflow( - expr = { - w <- workflow( - occurrence = UKAnophelesPlumbeus, - covariate = UKAir, - process = Chain(Background(n = 70), Crossvalidate), - model = ModelModule, - output = PerformanceMeasures, - forceReproducible = FALSE - ) - }, - placeholder = "ModelModule", - fun = roxy_parse$name - ) - if (inherits(w, what = "moduleError")) stop(w) - - expect_is(w, "zoonWorkflow", - info = paste("The model module did not work", - "in a crossvalidation workflow")) + SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE) + if(SDMtools_check){ + + # crossvalidate + w <- tryCatchWorkflow( + expr = { + w <- workflow( + occurrence = UKAnophelesPlumbeus, + covariate = UKAir, + process = Chain(Background(n = 70), Crossvalidate), + model = ModelModule, + output = PerformanceMeasures, + forceReproducible = FALSE + ) + }, + placeholder = "ModelModule", + fun = roxy_parse$name + ) + if (inherits(w, what = "moduleError")) stop(w) + + expect_is(w, "zoonWorkflow", + info = paste("The model module did not work", + "in a crossvalidation workflow")) + } } } } diff --git a/tests/testthat/testChangeWorkflow.R b/tests/testthat/testChangeWorkflow.R index aa9e85b..84aa26b 100644 --- a/tests/testthat/testChangeWorkflow.R +++ b/tests/testthat/testChangeWorkflow.R @@ -65,29 +65,31 @@ test_that("Basic ChangeWorkflow works", { "output = PrintMap, forceReproducible = FALSE)") )) - + # Change Process, model and output - set.seed(1) - w4 <- workflow( - UKAnophelesPlumbeus, - UKAir, - BackgroundAndCrossvalid(k = 2), - RandomForest, - PerformanceMeasures - ) - - set.seed(1) - w5 <- ChangeWorkflow( - w4, - process = Background(n = 70), - model = LogisticRegression, - output = PrintMap - ) - expect_true(all.equal( - w1[!names(w1) %in% "session.info"], - w5[!names(w5) %in% "session.info"] - )) - + suppressWarnings({SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE)}) + if(SDMtools_check){ + set.seed(1) + w4 <- workflow( + UKAnophelesPlumbeus, + UKAir, + BackgroundAndCrossvalid(k = 2), + RandomForest, + PerformanceMeasures + ) + + set.seed(1) + w5 <- ChangeWorkflow( + w4, + process = Background(n = 70), + model = LogisticRegression, + output = PrintMap + ) + expect_true(all.equal( + w1[!names(w1) %in% "session.info"], + w5[!names(w5) %in% "session.info"] + )) + } # Change occurrence and covariate set.seed(1) @@ -125,23 +127,26 @@ test_that("Basic ChangeWorkflow works", { # Only change output # Change Process, model and output - set.seed(1) - w7a <- workflow( - UKAnophelesPlumbeus, - UKAir, - Background(n = 70), - LogisticRegression, - PerformanceMeasures - ) - set.seed(1) - w7b <- ChangeWorkflow( - w7a, - output = PrintMap - ) - expect_true(all.equal( - w1[!names(w1) %in% "session.info"], - w7b[!names(w7b) %in% "session.info"] - )) + suppressWarnings({SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE)}) + if(SDMtools_check){ + set.seed(1) + w7a <- workflow( + UKAnophelesPlumbeus, + UKAir, + Background(n = 70), + LogisticRegression, + PerformanceMeasures + ) + set.seed(1) + w7b <- ChangeWorkflow( + w7a, + output = PrintMap + ) + expect_true(all.equal( + w1[!names(w1) %in% "session.info"], + w7b[!names(w7b) %in% "session.info"] + )) + } }) test_that("ChangeWorkflow - Chains", { diff --git a/tests/testthat/testcall_path.R b/tests/testthat/testcall_path.R index f8d2eea..7900807 100644 --- a/tests/testthat/testcall_path.R +++ b/tests/testthat/testcall_path.R @@ -491,6 +491,9 @@ test_that("Test call_path in a large number of variations", { ) ) + suppressWarnings({SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE)}) + if(!SDMtools_check) skip('Some tests require SDMtools - install it first') + CP_work4 <- workflow( occurrence = UKAnophelesPlumbeus, covariate = UKAir, diff --git a/tests/testthat/testsummary.zoonWorkflow.R b/tests/testthat/testsummary.zoonWorkflow.R index 0f17c12..c5e97a7 100644 --- a/tests/testthat/testsummary.zoonWorkflow.R +++ b/tests/testthat/testsummary.zoonWorkflow.R @@ -75,6 +75,9 @@ test_that("summary.zoonWorkflow tests", { class = "character" ) + suppressWarnings({SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE)}) + if(!SDMtools_check) skip(message = 'SDMtools required for some tests') + set.seed(1) expect_is( summary(workflow( diff --git a/tests/testthat/testtestModule.R b/tests/testthat/testtestModule.R index b23a39b..59eb7b5 100644 --- a/tests/testthat/testtestModule.R +++ b/tests/testthat/testtestModule.R @@ -17,24 +17,28 @@ test_that("repo modules pass", { expect_true(x <- zoon:::test_module(paste0(basepath, "Crossvalidate.R"))) - # Model PA - expect_true(x <- zoon:::test_module(paste0(basepath, - "LogisticRegression.R"))) - # Model PB - expect_true(x <- zoon:::test_module(paste0(basepath, - "MaxLike.R"))) + + # Covariate expect_true(x <- zoon:::test_module(paste0(basepath, "UKAir.R"))) - # Occurrence PO - expect_true(x <- zoon:::test_module(paste0(basepath, - "CarolinaWrenPO.R"))) + suppressWarnings({SDMtools_check <- requireNamespace('SDMtools', quietly = TRUE)}) + + if(!SDMtools_check) skip(message = 'SDMtools required for some tests - please install first') # Occurrence PA expect_true(x <- zoon:::test_module(paste0(basepath, "CWBZimbabwe.R"))) - + # Model PA + expect_true(x <- zoon:::test_module(paste0(basepath, + "LogisticRegression.R"))) + # Model PB + expect_true(x <- zoon:::test_module(paste0(basepath, + "MaxLike.R"))) + # Occurrence PO + expect_true(x <- zoon:::test_module(paste0(basepath, + "CarolinaWrenPO.R"))) }) diff --git a/zoon_package.Rproj b/zoon_package.Rproj index 9f96499..a159422 100644 --- a/zoon_package.Rproj +++ b/zoon_package.Rproj @@ -14,5 +14,6 @@ LaTeX: pdfLaTeX BuildType: Package PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source +PackageInstallArgs: --no-multiarch --with-keep.source --no-build-vignettes +PackageCheckArgs: --no-build-vignettes PackageRoxygenize: rd,collate,namespace