Skip to content

Commit

Permalink
Updates to address the archiving of SDMTools. This packaged is moved …
Browse files Browse the repository at this point in the history
…to suggests, tests that use it are skipped if it is not installed
  • Loading branch information
AugustT committed Feb 10, 2020
1 parent 3ff8856 commit 4ccd34c
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 157 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Tim", "Lucas", role = "aut", comment = c(ORCID = "0000-0003-4694-8107")),
Expand All @@ -24,15 +24,15 @@ Imports:
rgdal,
roxygen2,
rworldmap,
SDMTools,
sp,
testthat
Depends:
raster (>= 2.4-20),
R (>= 3.2.0)
Suggests:
knitr,
maxlike
maxlike,
SDMTools
VignetteBuilder: knitr
LazyData: TRUE
URL: https://github.com/zoonproject/zoon
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
215 changes: 114 additions & 101 deletions R/test_outputs.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#' @importFrom SDMTools auc confusion.matrix
#' @import randomForest
#'
# A function for testing the outputs conform to the expected
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ##
}
}
Expand Down Expand Up @@ -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") {

Expand Down Expand Up @@ -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"))
}
}
}
}
Expand Down
83 changes: 44 additions & 39 deletions tests/testthat/testChangeWorkflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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", {
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/testcall_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

3 comments on commit 4ccd34c

@timcdlucas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R packages seems to be falling fast at the moment.

@AugustT
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hoping to keep soon off the list, though it has been archived temporarily

@timcdlucas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hadn't seen we'd been archived already. Guess that has to happen as soon as a dependency is archived. Thanks for the great work!

Please sign in to comment.