Skip to content

Commit

Permalink
Updated almost all class tests for compatibility with the upcoming 4.…
Browse files Browse the repository at this point in the history
…0.0 R version
  • Loading branch information
Farewe committed Dec 12, 2019
1 parent 20b6633 commit 978703f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: virtualspecies
Type: Package
Title: Generation of Virtual Species Distributions
Version: 1.5
Date: 2019-04-30
Version: 1.5.1
Date: 2019-12-12
Author: Boris Leroy [cre, aut], Christine N. Meynard [ctb], Celine Bellard [ctb], Franck Courchamp [ctb], Robin Delsol [ctb], Willson Gaul [ctb]
Maintainer: Boris Leroy <[email protected]>
Description: Provides a framework for generating virtual species distributions,
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
virtualspecies v1.5.1 (Release date: 2019-12-12)
==============

Changes:
* Internal changes for compatibility with the upcoming R 4.0.0 version

virtualspecies v1.5 (Release date: 2019-04-30)
==============

Expand Down
10 changes: 5 additions & 5 deletions R/convertToPA.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ convertToPA <- function(x,
plot = TRUE)

{
if("virtualspecies" %in% class(x))
if(inherits(x, "virtualspecies"))
{
if("RasterLayer" %in% class(x$suitab.raster))
if(inherits(x$suitab.raster, "RasterLayer"))
{
sp.raster <- x$suitab.raster
} else stop("x must be:\n- a raster layer object\nor\n- the output list from functions
generateSpFromFun(), generateSpFromPCA() or generateRandomSp()")
} else if ("RasterLayer" %in% class(x))
} else if (inherits(x, "RasterLayer"))
{
sp.raster <- x
} else stop("x must be:\n- a raster layer object\nor\n- the output list from functions
Expand Down Expand Up @@ -685,7 +685,7 @@ convertToPA <- function(x,

species.prevalence <- cellStats(PA.raster, stat = "mean")

if("virtualspecies" %in% class(x))
if(inherits(x, "virtualspecies"))
{
if(PA.method == "threshold")
{
Expand Down Expand Up @@ -729,7 +729,7 @@ convertToPA <- function(x,
main = c("Environmental suitability",
"Probability of occurrence",
"Presence-absence"))
} else if ("RasterLayer" %in% class(x))
} else if (inherits(x, "RasterLayer"))
{
if(PA.method == "threshold")
{
Expand Down
2 changes: 1 addition & 1 deletion R/generateSpFromFun.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ generateSpFromFun <- function(raster.stack, parameters,
names(parameters)[i], "'. See help(generateSpFromFun) for more details.",
sep = "")}
test <- tryCatch(match.fun(parameters[[i]]$fun), error = function(c) "error")
if(class(test) != "function")
if(!inherits(test, "function"))
{
stop(paste("The function ", parameters[[i]]$fun, " does not exist, please verify spelling.", sep = ""))
}
Expand Down
12 changes: 6 additions & 6 deletions R/limitDistribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ limitDistribution <- function(x,
{


if("virtualspecies" %in% class(x))
if(inherits(x, "virtualspecies"))
{
if("RasterLayer" %in% class(x$pa.raster))
if(inherits(x$pa.raster, "RasterLayer"))
{
sp.raster <- x$pa.raster
results <- x
} else stop("x must be:\n- a raster layer object\nor\n- the output list from function convertToPA(), generateSpFromFun(), generateSpFromPCA() or generateRandomSp()")
} else if ("RasterLayer" %in% class(x))
} else if (inherits(x, "RasterLayer"))
{
sp.raster <- x
results <- list(sp.raster)
Expand Down Expand Up @@ -199,7 +199,7 @@ limitDistribution <- function(x,
# This is especially important given that randomPoints weights samplings by the cell area (because cells closer to
# the equator are larger)
{
if(!(class(area) %in% c("SpatialPolygons", "SpatialPolygonsDataFrame")))
if(!(inherits(area, c("SpatialPolygons", "SpatialPolygonsDataFrame"))))
{
stop("If you choose geographical.limit = 'polygon', please provide a polygon of class SpatialPolygons or SpatialPolygonsDataFrame to argument area")
}
Expand All @@ -208,15 +208,15 @@ limitDistribution <- function(x,
area = area)
} else if(geographical.limit == "extent")
{
if(!(class(area) == "Extent"))
if(!(inherits(area, "Extent")))
{
message("No object of class extent (or wrong object) provided: click twice on the map to draw the extent in which presence points will be sampled")
plot(sp.raster)
area <- drawExtent(show = TRUE)
}
} else if(geographical.limit == "raster")
{
if (!("RasterLayer" %in% class(area)))
if (!(inherits(area, "RasterLayer")))
{
stop("If you choose to limit the distribution with a raster, please provide the raster to argument 'area'")
}
Expand Down
2 changes: 1 addition & 1 deletion R/plotSuitabilityToProba.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

plotSuitabilityToProba <- function(sp, add = FALSE, ...)
{
if("virtualspecies" %in% class(sp))
if(inherits(sp, "virtualspecies"))
{
if(!("PA.conversion" %in% names(sp)))
{
Expand Down
24 changes: 12 additions & 12 deletions R/sampleOccurrences.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,18 @@ sampleOccurrences <- function(x, n,
attr(results, "seed") <- .Random.seed


if("virtualspecies" %in% class(x))
if(inherits(x, "virtualspecies"))
{
if("RasterLayer" %in% class(x$occupied.area))
if(inherits(x$occupied.area, "RasterLayer"))
{
sp.raster <- x$occupied.area
} else if("RasterLayer" %in% class(x$pa.raster))
} else if(inherits(x$pa.raster, "RasterLayer"))
{
sp.raster <- x$pa.raster
} else stop("x must be:\n- a raster layer object\nor\n- the output list from
functions generateRandomSp(), convertToPA() or
limitDistribution()")
} else if ("RasterLayer" %in% class(x))
} else if (inherits(x, "RasterLayer"))
{
sp.raster <- x
if(extract.probability)
Expand Down Expand Up @@ -361,9 +361,9 @@ sampleOccurrences <- function(x, n,
worldmap@data$SOVEREIGNT %in% sampling.area |
worldmap@data$REGION %in% sampling.area |
worldmap@data$continent %in% sampling.area), ]
} else if(!(class(sampling.area) %in% c("SpatialPolygons",
"SpatialPolygonsDataFrame",
"Extent")))
} else if(!(inherits(sampling.area, c("SpatialPolygons",
"SpatialPolygonsDataFrame",
"Extent"))))
{
stop("Please provide to sampling.area either \n
- the names of countries, region and/or continents in which to sample\n
Expand All @@ -383,7 +383,7 @@ sampleOccurrences <- function(x, n,

if(correct.by.suitability)
{
if(!("virtualspecies" %in% class(x)) | !("suitab.raster" %in% names(x)))
if(!(inherits(x, "virtualspecies")) | !("suitab.raster" %in% names(x)))
{
stop("If you choose to weight the probability of detection by the suitability of the species (i.e., correct.by.suitability = TRUE),
then you need to provide an appropriate virtual species containing a suitability raster to x.")
Expand Down Expand Up @@ -469,8 +469,8 @@ sampleOccurrences <- function(x, n,
# This is especially important given that randomPoints weights samplings by
# the cell area (because cells closer to the equator are larger)
{
if(!(class(bias.area) %in% c("SpatialPolygons",
"SpatialPolygonsDataFrame")))
if(!(inherits(bias.area, c("SpatialPolygons",
"SpatialPolygonsDataFrame"))))
{
stop("If you choose bias = 'polygon', please provide a polygon of class
SpatialPolygons or SpatialPolygonsDataFrame to argument bias.area")
Expand Down Expand Up @@ -503,7 +503,7 @@ sampleOccurrences <- function(x, n,

if (bias == "manual")
{
if(!("RasterLayer" %in% class(weights)))
if(!(inherits(weights, "RasterLayer")))
{
stop("You must provide a raster layer of weights (to argument weights)
if you choose bias == 'manual'")
Expand Down Expand Up @@ -546,7 +546,7 @@ sampleOccurrences <- function(x, n,
bias.raster <- bias.raster * bias.raster1
} else if(bias == "extent")
{
if(!(class(bias.area) == "Extent"))
if(!(inherits(bias.area, "Extent")))
{
message("No object of class extent provided: click twice on the map to draw the extent in which presence points will be sampled")
plot(sp.raster)
Expand Down
4 changes: 2 additions & 2 deletions R/utilityFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}
}

if (class(ext)=='character') {
if (inherits(ext, 'character')) {
if (! ext %in% c('points')) {
stop("if ext is a character variable it should be 'points'")
} else if (missing(p)) {
Expand All @@ -92,7 +92,7 @@
stopifnot(hasValues(mask))
cells <- crop(mask, mask2)
cells <- try( stats::na.omit(cbind(1:ncell(cells), getValues(cells))))
if (class(cells) == 'try-error') {
if (inherits(cells, 'try-error')) {
stop("the raster is too large to be used with 'prob=TRUE'")
}
prob <- cells[,2]
Expand Down

0 comments on commit 978703f

Please sign in to comment.