From f658de0821d0ce14b77cf2ca040dabdf4e0f2f09 Mon Sep 17 00:00:00 2001 From: Johanna Paijmans Date: Thu, 28 Sep 2023 12:39:35 +0100 Subject: [PATCH 1/6] Detailed warning messages sampling pseudoabs --- R/sample_pseudoabs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sample_pseudoabs.R b/R/sample_pseudoabs.R index d5caebd2..19cc9747 100644 --- a/R/sample_pseudoabs.R +++ b/R/sample_pseudoabs.R @@ -100,7 +100,7 @@ sample_pseudoabs <- function (data, raster, n, coords = NULL, if (length(cell_id)>n){ cell_id <- sample(x= cell_id, size = n) } else { - warning("There are fewer available cells in the raster than the requested ", n, " points.\n", + warning("There are fewer available cells in raster for raster \"",time(sampling_raster),"\" (",nrow(xy_pres)," presences) than the requested ", n, " points.\n", "Only ", length(cell_id), " will be returned.") } pseudoabsences <- as.data.frame (terra::xyFromCell(sampling_raster, cell_id)) From 05b2bdb676d37c2c58fd5cbc40f2318a5874e09f Mon Sep 17 00:00:00 2001 From: Johanna Paijmans Date: Thu, 28 Sep 2023 12:46:07 +0100 Subject: [PATCH 2/6] Detailed warning messages sampling pseudoabs --- R/sample_pseudoabs.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/sample_pseudoabs.R b/R/sample_pseudoabs.R index 19cc9747..4c373af8 100644 --- a/R/sample_pseudoabs.R +++ b/R/sample_pseudoabs.R @@ -100,8 +100,7 @@ sample_pseudoabs <- function (data, raster, n, coords = NULL, if (length(cell_id)>n){ cell_id <- sample(x= cell_id, size = n) } else { - warning("There are fewer available cells in raster for raster \"",time(sampling_raster),"\" (",nrow(xy_pres)," presences) than the requested ", n, " points.\n", - "Only ", length(cell_id), " will be returned.") + warning("There are fewer available cells in raster for raster \"",time(sampling_raster),"\" (",nrow(xy_pres)," presences) than the requested ", n, " points. Only ", length(cell_id), " will be returned.\n") } pseudoabsences <- as.data.frame (terra::xyFromCell(sampling_raster, cell_id)) # fix the coordinate names to be the same we started with From 98cd3f862906d9f466765904fdde74e4f89bd7fc Mon Sep 17 00:00:00 2001 From: Johanna Paijmans Date: Wed, 4 Oct 2023 10:00:07 +0100 Subject: [PATCH 3/6] More detailed error message pseudoabs sampling --- tests/testthat/test_sample_pseudoabs.R | 2 +- tests/testthat/testthat-problems.rds | Bin 0 -> 14510 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 tests/testthat/testthat-problems.rds diff --git a/tests/testthat/test_sample_pseudoabs.R b/tests/testthat/test_sample_pseudoabs.R index 4f828d7e..103eeae7 100644 --- a/tests/testthat/test_sample_pseudoabs.R +++ b/tests/testthat/test_sample_pseudoabs.R @@ -82,7 +82,7 @@ test_that("handling of data frames and sf objects", { expect_error(sample_pseudoabs(locations_sf, coords = c("x", "y"), raster = grid_raster), "There are no recognised coordinate columns") expect_warning(sample_pseudoabs(locations_sf, raster = grid_raster, n = 100), - "There are fewer available cells in the raster than the requested 100 points") + "There are fewer available cells in raster for raster 'NA' (3 presences) than the requested 100 points. Only 52 will be returned.") locations_sf <- locations_sf %>% dplyr::bind_cols(sf::st_coordinates(.)) expect_no_error(sample_pseudoabs(locations_sf, coords = c("X", "Y"), raster = grid_raster, n = 25)) locations_sf$X <- rep(0, 3) diff --git a/tests/testthat/testthat-problems.rds b/tests/testthat/testthat-problems.rds new file mode 100644 index 0000000000000000000000000000000000000000..21e673b530bae9f0c79e5ab5f1fe5ca67204abc2 GIT binary patch literal 14510 zcmZ{LdpwivAOG__o#t{d)C!;dbx7uIqDsKJU-_{l0FhNm76O{l`YWhby!epFyLkI7<{ugN;j?GDuW~o=tUWhG_Ip3Dj0__iG92egCk2IAp2Zf>d;^JS{LOI`ZbvK~Tl@9ZzFq7miKluYx`GkxwJS>BVk>>Bc- z;B&=mj}z4S5MJKY2sVAnu0F5erh!Vz>bXX{b1|uYTj22KQEZ zxi04Ko^B;+Z8v4bkXNVd8f41q*D87l88;`P-q^9X4(1Q40xcf*lnUHU%lb|td%FJn zM?S(;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