Skip to content

Commit 10e5607

Browse files
committed
update 3.1.6 issues #50 and #54
1 parent 9f796b6 commit 10e5607

28 files changed

+5169
-5125
lines changed

.gitignore

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
.Rproj.user
2-
.Rhistory
3-
.RData
4-
Meta
5-
cran_comments.md
6-
tests/testthat/Rplots.pdf
7-
vignettes/tutorial_1.R
8-
vignettes/tutorial_1.html
9-
vignettes/tutorial_2.R
10-
vignettes/tutorial_2.html
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
Meta
5+
cran_comments.md
6+
tests/testthat/Rplots.pdf
7+
revdep
8+
revdep/*
9+
vignettes/tutorial_1.R
10+
vignettes/tutorial_1.html
11+
vignettes/tutorial_2.R
12+
vignettes/tutorial_2.html

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: blockCV
22
Type: Package
33
Title: Spatial and Environmental Blocking for K-Fold and LOO Cross-Validation
4-
Version: 3.1-5
5-
Date: 2024-10-31
4+
Version: 3.1-6
5+
Date: 2025-06-23
66
Authors@R: c(person("Roozbeh", "Valavi", role = c("aut", "cre"),
77
email = "valavi.r@gmail.com", comment = c(ORCID = "0000-0003-2495-5277")),
88
person("Jane", "Elith", role = "aut",

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# version 3.1.6
2+
* Resolved unclear error messages; issue [#52](https://github.com/rvalavi/blockCV/issues/52) by A. Márcia Barbosa
3+
* Resolved ggplot testing failure; issue [#54](https://github.com/rvalavi/blockCV/issues/54) by Teun van den Brand
4+
15
# version 3.1.5
26
* Resolved background pattern artifacts in raster plotting; issue [#50](https://github.com/rvalavi/blockCV/issues/50) by Camila Neder.
37

R/blockCV.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#' @references Valavi, R., Elith, J., Lahoz-Monfort, J. J., & Guillera-Arroita, G. (2019). blockCV: An R package for generating spatially or environmentally separated folds for k-fold cross-validation of species distribution models. Methods in Ecology and Evolution, 10(2), 225-232. doi:10.1111/2041-210X.13107.
2323
#'
2424
#' @name blockCV
25-
#' @docType package
2625
#' @author Roozbeh Valavi, Jane Elith, José Lahoz-Monfort, Ian Flint, and Gurutzeta Guillera-Arroita
2726
#' @import sf
28-
NULL
27+
"_PACKAGE"

R/checks.R

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,110 +6,111 @@
66

77
# check points fall within the raster layer
88
.check_within <- function(x, r) {
9-
bbox <- sf::st_bbox(x)
10-
ex <- terra::ext(r)
9+
bbox <- sf::st_bbox(x)
10+
ex <- terra::ext(r)
1111

12-
y <- bbox[1] >= terra::xmin(ex) &
13-
bbox[3] <= terra::xmax(ex) &
14-
bbox[2] >= terra::ymin(ex) &
15-
bbox[4] <= terra::ymax(ex)
12+
y <- bbox[1] >= terra::xmin(ex) &
13+
bbox[3] <= terra::xmax(ex) &
14+
bbox[2] >= terra::ymin(ex) &
15+
bbox[4] <= terra::ymax(ex)
1616

17-
if(!y) stop("The x's bounding box lies outside the raster extent.")
17+
if(!y) stop("The x's bounding box lies outside the raster extent.")
1818
}
1919

2020

2121
# check for x
2222
.check_x <- function(x, name = "x"){
23-
if(!methods::is(x, "sf")){
24-
tryCatch(
25-
{
26-
x <- sf::st_as_sf(x)
27-
},
28-
error = function(cond) {
29-
message(sprintf("'%s' is not convertible to an sf object!", name))
30-
message(sprintf("'%s' must be an sf or spatial* object.", name))
31-
}
32-
)
33-
}
34-
return(x)
23+
if(!methods::is(x, "sf")){
24+
tryCatch(
25+
{
26+
x <- sf::st_as_sf(x)
27+
},
28+
error = function(cond) {
29+
message(sprintf("'%s' is not convertible to an sf object!", name))
30+
message(sprintf("'%s' must be an sf or spatial* object.", name))
31+
}
32+
)
33+
}
34+
return(x)
3535
}
3636

3737
# check for column matching colnames(x)
3838
.check_column <- function(column, x){
39-
if(!is.null(column)){
40-
if(!column %in% colnames(x)){
41-
warning(sprintf("There is no column named '%s' in 'x'. Column is ignored!\n", column))
42-
column <- NULL
39+
if(!is.null(column)){
40+
if(!column %in% colnames(x)){
41+
warning(sprintf("There is no column named '%s' in 'x'. Column is ignored!\n", column))
42+
column <- NULL
43+
}
4344
}
44-
}
45-
return(column)
45+
return(column)
4646
}
4747

4848
# column should be binary or categorical
4949
.check_classes <- function(clen, column, th = 15){
50-
if(clen > th){
51-
warning(
52-
sprintf(
53-
paste(
54-
"The are too many unique values in '%s'.",
55-
"Use 'column' only for binary or categorical responses (ignore this if it is).\n"
56-
),
57-
column
58-
)
59-
)
60-
}
50+
if(clen > th){
51+
warning(
52+
sprintf(
53+
paste(
54+
"The are too many unique values in '%s'.",
55+
"Use 'column' only for binary or categorical responses (ignore this if it is).\n"
56+
),
57+
column
58+
)
59+
)
60+
}
6161
}
6262

6363

6464
# check raster extent is valid
6565
.check_ext <- function(r) {
66-
tryCatch(
67-
{
68-
e <- terra::ext(r)
69-
vals <- e[1:4]
70-
},
71-
error = function(cond) {
72-
stop("Failed to extract raster extent: ", conditionMessage(cond))
73-
}
74-
)
66+
tryCatch(
67+
{
68+
e <- terra::ext(r)
69+
vals <- e[1:4]
70+
},
71+
error = function(cond) {
72+
stop("Failed to extract raster extent: ", conditionMessage(cond))
73+
}
74+
)
7575

76-
y <- all(is.finite(vals)) &&
77-
(terra::xmax(e) > terra::xmin(e)) &&
78-
(terra::ymax(e) > terra::ymin(e))
76+
y <- all(is.finite(vals)) &&
77+
(terra::xmax(e) > terra::xmin(e)) &&
78+
(terra::ymax(e) > terra::ymin(e))
7979

80-
if (!y) stop("Invalid raster extent: values are non-finite, degenerate, or out of range.")
80+
if (!y) stop("Invalid raster extent: values are non-finite or out of range.")
8181
}
8282

8383
# check for r
8484
.check_r <- function(r, name = "r"){
85-
if(!methods::is(r, "SpatRaster")){
86-
tryCatch(
87-
{
88-
r <- terra::rast(r)
89-
},
90-
error = function(cond) {
91-
message(sprintf("'%s' is not convertible to a terra SpatRaster object!", name))
92-
message(sprintf("'%s' must be a SpatRaster, stars, Raster* object, or path to a raster file on disk.", name))
93-
}
94-
)
95-
}
96-
.check_ext(r) # check for valid extent
85+
if(!methods::is(r, "SpatRaster")){
86+
tryCatch(
87+
{
88+
r <- terra::rast(r)
89+
},
90+
error = function(cond) {
91+
message(sprintf("'%s' is not convertible to a terra SpatRaster object!", name))
92+
message(sprintf("'%s' must be a SpatRaster, stars, Raster* object, or path to a raster file on disk.", name))
93+
}
94+
)
95+
}
96+
# check for a valid extent
97+
.check_ext(r)
9798

98-
return(r)
99+
return(r)
99100
}
100101

101102
# check for required packages
102103
.check_pkgs <- function(pkg){
103-
pkgna <- names(which(sapply(sapply(pkg, find.package, quiet = TRUE), length) == 0))
104-
if(length(pkgna) > 0){
105-
nm <- paste(pkgna, collapse = ", ")
106-
message("This function requires these packages: ", nm, "\nWould you like to install them now?\n1: yes\n2: no")
107-
user <- readline(prompt = paste0("Selection: "))
108-
if(tolower(user) %in% c("1", "yes", "y")){
109-
utils::install.packages(pkgna)
110-
} else{
111-
stop("Please install these packages for function to work: ", nm)
104+
pkgna <- names(which(sapply(sapply(pkg, find.package, quiet = TRUE), length) == 0))
105+
if(length(pkgna) > 0){
106+
nm <- paste(pkgna, collapse = ", ")
107+
message("This function requires these packages: ", nm, "\nWould you like to install them now?\n1: yes\n2: no")
108+
user <- readline(prompt = paste0("Selection: "))
109+
if(tolower(user) %in% c("1", "yes", "y")){
110+
utils::install.packages(pkgna)
111+
} else{
112+
stop("Please install these packages for function to work: ", nm)
113+
}
112114
}
113-
}
114115
}
115116

0 commit comments

Comments
 (0)