From 80ad43b04794f2355a1b533ba6e70fd666336f21 Mon Sep 17 00:00:00 2001 From: BrunoVilela Date: Thu, 3 Aug 2023 14:02:52 +0200 Subject: [PATCH] Adjusting tests --- .DS_Store | Bin 14340 -> 14340 bytes R/lets_presab_birds.R | 5 +++- man/lets.presab.birds.Rd | 5 +++- tests/.DS_Store | Bin 8196 -> 8196 bytes tests/testthat/test-lets_distmat.R | 17 ------------ tests/testthat/test-lets_gridirizer.R | 4 +-- tests/testthat/test-lets_maplizer.R | 2 +- tests/testthat/test-lets_presab.R | 34 +++++++++++++++++------- tests/testthat/test-lets_presab_birds.R | 18 ++++++------- 9 files changed, 44 insertions(+), 41 deletions(-) diff --git a/.DS_Store b/.DS_Store index 8d81c9ae38b393bc108fa338df981456ac3ebd0c..dcf19e97523ba9f6a2a9956e9c25d7bda0ec1269 100644 GIT binary patch delta 181 zcmZoEXeromO_1^USEQ^#^z=^3I?@03e{$Y7CH*%=H|7voE+k+hPIvwxs_Gb uHMMoqCpQYoGtSt&P-qD&SsM8y|FTVNVA;&Au!lpLc>6%wHnSW2Wd{J$^Evkb delta 210 zcmZoEXeromO_1@_wRN*5%L~dg&fYvvXbG$6iKK#@%;FLQgX@e;%q*;I>>M0i9Fs39W$18l#tVp7 zR~uQH>L^%PfQ&RZH_%ZqF*d_6aR%7LnVY#J|FUi7R@lR#PO842Y@68){;~rA^U^+k diff --git a/R/lets_presab_birds.R b/R/lets_presab_birds.R index f020df8..e57ae2b 100644 --- a/R/lets_presab_birds.R +++ b/R/lets_presab_birds.R @@ -6,7 +6,10 @@ #' @description Convert species' ranges (in shapefile format and stored in #' particular folders) into a presence-absence matrix based on a user-defined #' grid. This function is specially designed to work with BirdLife Intl. -#' shapefiles (\url{https://www.birdlife.org}). +#' shapefiles (\url{https://www.birdlife.org}). (Notice that new versions of +#' birds spatial data are in a similar format to other groups and should be +#' run using the lets.presab function. We will keep this function in case +#' someone needs to use on the previous data format.) #' #' @inheritParams lets.presab #' @param path Path location of folders with one or more species' individual diff --git a/man/lets.presab.birds.Rd b/man/lets.presab.birds.Rd index 1f9c816..2b8313f 100644 --- a/man/lets.presab.birds.Rd +++ b/man/lets.presab.birds.Rd @@ -91,7 +91,10 @@ The result is a list object of class \code{\link{PresenceAbsence}} Convert species' ranges (in shapefile format and stored in particular folders) into a presence-absence matrix based on a user-defined grid. This function is specially designed to work with BirdLife Intl. - shapefiles (\url{https://www.birdlife.org}). + shapefiles (\url{https://www.birdlife.org}). (Notice that new versions of + birds spatial data are in a similar format to other groups and should be + run using the lets.presab function. We will keep this function in case + someone needs to use on the previous data format.) } \details{ The function creates the presence-absence matrix based on a raster diff --git a/tests/.DS_Store b/tests/.DS_Store index bf01b1ed68ed56a89f81aa07809b1e7ad7103f6d..91ae8ff1d6769f9d89db12043adad8039fe5e2d9 100644 GIT binary patch delta 1146 zcmeH^OGuPa7>2)hy!}UydgkKHIF6Z^*9^x?ifHh(&2 zXiXJ+z_bamxA0nPx8E1&b-CtY2n&yhj8a&143BlVYu$DAyhWJ$eBJ|%-Mzl9&cJqW zPe4{}g=L>sXf)ac*kqi|nVO!HS5#V26^s`~6Sr{ft+5_l%Q3l1cvHaF?-d?}1x>;j zzdD!mrgmRvn+P!d#Fft-&3;d-*DuvI%Al)p#<%TjwENMGgncBA=L0ZXFih(M3|lx@nS{777=<{ z%FCG4A;R^vf~$(CXCg9~l<2T;sN!6ZSYS*^Th@g1w7iPPG)M2HhF>5=A_ivIk&0~O zp;UrbQH5%348h-uZD_{MB?0Y{e+Rm75Qi{;!#E-x91l4d#%Y|vIh@A@Tq(ymu3|#! zn8pll;+E8M2M_U7DtV><+<>JC8vab8SG=AYw)SJ>sC6pJ{v$kUkzewEvj38-`8VCA B^KbwF delta 1248 zcmeIxTS!zv7zgn0zuwMqQfF6P*L5XjF>hsSW|?`}Rx9&Xi4r|z?dAbDw{`8Tic;;1 zL}m1HprQ-bOJWxY%pxm@pdf-MT?j*{2w#m73L>iGITjS*Q;*HVe9V0F@Xhy|8E_6b zZ&Y#!ij%ji^9bKpIPMAfymHXtcm+d5WK?vFAjUElXRX;%TUXz(oAYj2YLa~Jptnb= zb_XR{*<|ceij0Y7QM?+TV$00RTe*5&MO8R~8%->UDX)!nU`oEpQO}xXZ@Sp=Xik$Okx@{n8h5v>O~r`P<-RhOXv~b)F@DpB$CxRNbTgN zpik}zlz4od9wNig-^pwmS?(fa$)Y$FKkt;7lx$AP$jU1yDk*m<*OOWdY^n0bXi;p* znIV>K%N6;Uz!A2jTGMRVwiSZF4cdY^Y^y|7lt<{fVzyRL?Rb=)EoEh*s>>twY$e+u zsE9l|oR(^}R8=#^iO-3mU|&Qs^c&@(kWXlW-l~XS=sThi3lmb1fgBW|L}jal3su;t z(QQW)nz3s^Z!dh<4?hCvLq87U5JH;ZAWq<94Nl_>&f**{;4+3WqGDdd7;dYi;~MHC sJi|*&>s-GW8~$LN8SORqV>HI{DblDuX6=RQZAt&%Z1ubR^Je$r2XoW~6aWAK diff --git a/tests/testthat/test-lets_distmat.R b/tests/testthat/test-lets_distmat.R index 2f7db1b..520c021 100644 --- a/tests/testthat/test-lets_distmat.R +++ b/tests/testthat/test-lets_distmat.R @@ -25,20 +25,3 @@ test_that("lets.distmat works fine, asdist = FALSE", { }) -test_that("lets.distmat works fine, miles = TRUE", { - - - distPAM <- lets.distmat(PAM, miles = TRUE) - expect_true(class(distPAM)[1] == "dist") - expect_true(all(dim(as.matrix(distPAM)) == dimPAM)) - -}) - -test_that("lets.distmat works fine, xy as matrix ", { - - - distPAM <- lets.distmat(coords, miles = TRUE) - expect_true(class(distPAM)[1] == "dist") - expect_true(all(dim(as.matrix(distPAM)) == nrow(coords))) - -}) diff --git a/tests/testthat/test-lets_gridirizer.R b/tests/testthat/test-lets_gridirizer.R index ebd841b..0903d79 100644 --- a/tests/testthat/test-lets_gridirizer.R +++ b/tests/testthat/test-lets_gridirizer.R @@ -7,7 +7,7 @@ test_that("lets.gridirizer works fine", { resu_test <- lets.gridirizer(PAM) expect_equal(class(resu_test)[1], "list") - expect_true(inherits(resu_test[[1]], "SpatialPolygonsDataFrame")) - expect_equal(class(resu_test[[2]])[1], "matrix") + expect_true(inherits(resu_test[[1]], "SpatVector")) + expect_equal(class(resu_test[[2]])[1], "data.frame") }) diff --git a/tests/testthat/test-lets_maplizer.R b/tests/testthat/test-lets_maplizer.R index c90576b..413a792 100644 --- a/tests/testthat/test-lets_maplizer.R +++ b/tests/testthat/test-lets_maplizer.R @@ -23,7 +23,7 @@ test_that("lets.maplizer works fine", { resu_test <- lets.maplizer(PAM, trait, PAM$S, ras = TRUE) expect_equal(class(resu_test)[1], "list") expect_equal(class(resu_test[[1]])[1], "matrix") - expect_true(inherits(resu_test[[2]], "RasterLayer")) + expect_true(inherits(resu_test[[2]], "SpatRaster")) expect_true(ncol(resu_test[[1]]) == 3) }) diff --git a/tests/testthat/test-lets_presab.R b/tests/testthat/test-lets_presab.R index 232b9a0..5b87103 100644 --- a/tests/testthat/test-lets_presab.R +++ b/tests/testthat/test-lets_presab.R @@ -4,10 +4,24 @@ data(Phyllomedusa) test_that("lets.presab return a correct PresenceAbsence object", { skip_on_cran() - PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15, - resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, - origin=NULL, seasonal=NULL, count=FALSE) + PAM <- + lets.presab( + Phyllomedusa, + xmn = -93, + xmx = -29, + ymn = -57, + ymx = 15, + resol = 1, + remove.cells = TRUE, + remove.sp = TRUE, + show.matrix = FALSE, + crs = terra::crs("+proj=longlat +datum=WGS84"), + cover = 0, + presence = NULL, + origin = NULL, + seasonal = NULL, + count = FALSE + ) expect_equal(class(PAM), "PresenceAbsence") expect_true(is.matrix(PAM[[1]])) expect_true(inherits(PAM[[2]], "SpatRaster")) @@ -21,7 +35,7 @@ test_that("lets.presab return a correct PresenceAbsence object for the world", { PAM <- lets.presab(Phyllomedusa, resol=5, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) @@ -40,7 +54,7 @@ test_that("lets.presab return a correct PresenceAbsence object (count=TRUE)", { PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15, resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, origin=NULL, seasonal=NULL, count=TRUE) expect_equal(class(PAM), "PresenceAbsence") @@ -57,7 +71,7 @@ test_that("lets.presab return a correct PresenceAbsence object, cover=0.2", { PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15, resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM), "PresenceAbsence") @@ -74,7 +88,7 @@ test_that("lets.presab return a correct PresenceAbsence object different project pro <- paste("+proj=eqdc +lat_0=-32 +lon_0=-60 +lat_1=-5", "+lat_2=-42 +x_0=0 +y_0=0 +ellps=aust_SA", "+units=m +no_defs") - SA_EC <- CRS(pro) + SA_EC <- terra::crs(pro) PAM_proj <- lets.presab(shapes = Phyllomedusa, xmn = -4135157, xmx = 4707602, @@ -97,7 +111,7 @@ test_that("lets.presab return a correct PresenceAbsence object, remove.sp=FALSE" PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15, resol=1, remove.cells=TRUE, remove.sp=FALSE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM), "PresenceAbsence") @@ -117,7 +131,7 @@ test_that("lets.presab return a correct PresenceAbsence object, remove.cells=FAL PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15, resol=1, remove.cells=FALSE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM), "PresenceAbsence") diff --git a/tests/testthat/test-lets_presab_birds.R b/tests/testthat/test-lets_presab_birds.R index 6affdba..f502531 100644 --- a/tests/testthat/test-lets_presab_birds.R +++ b/tests/testthat/test-lets_presab_birds.R @@ -7,7 +7,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object", { skip_on_cran() PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25, resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM)[1], "PresenceAbsence") @@ -21,7 +21,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object for the wor skip_on_cran() PAM <- lets.presab.birds(path.Ramphastos, resol=5, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM), "PresenceAbsence") @@ -38,7 +38,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object for cover d pro <- paste("+proj=eqdc +lat_0=-32 +lon_0=-60 +lat_1=-5", "+lat_2=-42 +x_0=0 +y_0=0 +ellps=aust_SA", "+units=m +no_defs") - SA_EC <- suppressWarnings(CRS(pro)) + SA_EC <- suppressWarnings(terra::crs(pro)) PAM3 <- lets.presab.birds(path.Ramphastos, xmn = -4135157, xmx = 4707602, @@ -60,7 +60,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object (count=TRUE PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25, resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, origin=NULL, seasonal=NULL, count=TRUE) expect_equal(class(PAM), "PresenceAbsence") expect_true(is.matrix(PAM[[1]])) @@ -74,7 +74,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object, cover=0.2" PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25, resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM), "PresenceAbsence") @@ -92,7 +92,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object, PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25, resol=1, remove.cells=TRUE, remove.sp=FALSE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover = 0.999999, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover = 0.999999, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM), "PresenceAbsence") expect_true(is.matrix(PAM[[1]])) @@ -106,7 +106,7 @@ test_that("lets.presab.birdsreturn a correct PresenceAbsence object, remove.cell PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25, resol=1, remove.cells=FALSE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, origin=NULL, seasonal=NULL, count=FALSE) expect_equal(class(PAM), "PresenceAbsence") @@ -124,12 +124,12 @@ test_that("lets.presab.birdsreturn a correct PresenceAbsence object, remove.cell test_that("lets.presab.birds new projection", { skip_on_cran() - desiredcrs <- CRS("+proj=laea +lat_0=0 +lon_0=-80 +x_0=180 +y_0=70 +units=km") + desiredcrs <- terra::crs("+proj=laea +lat_0=0 +lon_0=-80 +x_0=180 +y_0=70 +units=km") PAM <- lets.presab.birds(path.Ramphastos, xmn = -3000, xmx = 6000, ymn = -5000, ymx = 3000, res = 100, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE, - crs=CRS("+proj=longlat +datum=WGS84"), cover=0, + crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL, crs.grid = desiredcrs, origin=NULL, seasonal=NULL, count=TRUE)