Skip to content

Commit

Permalink
added test skips in absence of JAGS
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanCarbone committed Apr 4, 2024
1 parent 11eb01e commit c55f2d3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 60 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ Suggests:
R2jags,
roxygen2,
testthat (>= 0.8.0)
BRCindicators
VignetteBuilder:
knitr
Encoding: UTF-8
remotes: BiologicalRecordsCentre/BRCindicators
LazyData: TRUE
RoxygenNote: 7.2.3
SystemRequirements: JAGS
Expand Down
133 changes: 73 additions & 60 deletions tests/testthat/test-occurrenceChange.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
test_that("Test errors and warnings", {

# Create a small dataset
n <- 15000 #size of dataset
nyr <- 20 # number of years in data
nSamples <- 100 # set number of dates
nSites <- 50 # set number of sites
set.seed(seed = 648)

# Create somes dates
first <- as.Date(strptime("1980/01/01", "%Y/%m/%d"))
last <- as.Date(strptime(paste(1980+(nyr-1),"/12/31", sep=''), "%Y/%m/%d"))
dt <- last-first
rDates <- first + (runif(nSamples)*dt)

# taxa are set as random letters
taxa <- sample(letters, size = n, TRUE)

# three sites are visited randomly
site <- sample(paste('A', 1:nSites, sep=''), size = n, TRUE)

# the date of visit is selected at random from those created earlier
survey <- sample(rDates, size = n, TRUE)

# run with regions
# Create region definitions
regions <- data.frame(site = unique(site),
region1 = c(rep(1, 20), rep(0, 30)),
region2 = c(rep(0, 20), rep(1, 15), rep(0, 15)),
region3 = c(rep(0, 20), rep(0, 15), rep(1, 15)))

# skip the test if jagsUI is not installed
if ((!requireNamespace("jagsUI", quietly = TRUE))) {
skip("jagsUI software not available")
}

# Create a small dataset
n <- 15000 # size of dataset
nyr <- 20 # number of years in data
nSamples <- 100 # set number of dates
nSites <- 50 # set number of sites
set.seed(seed = 648)

# Create somes dates
first <- as.Date(strptime("1980/01/01", "%Y/%m/%d"))
last <- as.Date(strptime(paste(1980 + (nyr - 1), "/12/31", sep = ""), "%Y/%m/%d"))
dt <- last - first
rDates <- first + (runif(nSamples) * dt)

# taxa are set as random letters
taxa <- sample(letters, size = n, TRUE)

# three sites are visited randomly
site <- sample(paste("A", 1:nSites, sep = ""), size = n, TRUE)

# the date of visit is selected at random from those created earlier
survey <- sample(rDates, size = n, TRUE)

# run with regions
# Create region definitions
regions <- data.frame(
site = unique(site),
region1 = c(rep(1, 20), rep(0, 30)),
region2 = c(rep(0, 20), rep(1, 15), rep(0, 15)),
region3 = c(rep(0, 20), rep(0, 15), rep(1, 15))
)

# run the model with these data for one species
suppressWarnings(results <- occDetModel(
suppressWarnings(results <- occDetModel(
taxa = taxa,
site = site,
survey = survey,
Expand Down Expand Up @@ -69,38 +76,44 @@ regions <- data.frame(site = unique(site),
})

test_that("Test occurrenceChange functionality", {

# Create a small dataset
n <- 15000 #size of dataset
nyr <- 20 # number of years in data
nSamples <- 100 # set number of dates
nSites <- 50 # set number of sites
set.seed(seed = 648)

# Create somes dates
first <- as.Date(strptime("1980/01/01", "%Y/%m/%d"))
last <- as.Date(strptime(paste(1980+(nyr-1),"/12/31", sep=''), "%Y/%m/%d"))
dt <- last-first
rDates <- first + (runif(nSamples)*dt)

# taxa are set as random letters
taxa <- sample(letters, size = n, TRUE)

# three sites are visited randomly
site <- sample(paste('A', 1:nSites, sep=''), size = n, TRUE)

# the date of visit is selected at random from those created earlier
survey <- sample(rDates, size = n, TRUE)

# run with regions
# Create region definitions
regions <- data.frame(site = unique(site),
region1 = c(rep(1, 20), rep(0, 30)),
region2 = c(rep(0, 20), rep(1, 15), rep(0, 15)),
region3 = c(rep(0, 20), rep(0, 15), rep(1, 15)))
# skip the test if jagsUI is not installed
if ((!requireNamespace("jagsUI", quietly = TRUE))) {
skip("jagsUI software not available")
}

# Create a small dataset
n <- 15000 # size of dataset
nyr <- 20 # number of years in data
nSamples <- 100 # set number of dates
nSites <- 50 # set number of sites
set.seed(seed = 648)

# Create somes dates
first <- as.Date(strptime("1980/01/01", "%Y/%m/%d"))
last <- as.Date(strptime(paste(1980 + (nyr - 1), "/12/31", sep = ""), "%Y/%m/%d"))
dt <- last - first
rDates <- first + (runif(nSamples) * dt)

# taxa are set as random letters
taxa <- sample(letters, size = n, TRUE)

# three sites are visited randomly
site <- sample(paste("A", 1:nSites, sep = ""), size = n, TRUE)

# the date of visit is selected at random from those created earlier
survey <- sample(rDates, size = n, TRUE)

# run with regions
# Create region definitions
regions <- data.frame(
site = unique(site),
region1 = c(rep(1, 20), rep(0, 30)),
region2 = c(rep(0, 20), rep(1, 15), rep(0, 15)),
region3 = c(rep(0, 20), rep(0, 15), rep(1, 15))
)

# run the model with these data for one species
suppressWarnings(results <- occDetModel(
suppressWarnings(results <- occDetModel(
taxa = taxa,
site = site,
survey = survey,
Expand Down

0 comments on commit c55f2d3

Please sign in to comment.