Skip to content

Commit f52ba02

Browse files
authored
Merge pull request #56 from rvalavi/v3.2
V3.2 update
2 parents 484b5c6 + 4afe59d commit f52ba02

32 files changed

+1305
-959
lines changed

.github/workflows/R-CMD-check.yml

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
on:
2-
push:
3-
branches: [ master ]
4-
pull_request:
5-
branches: [ master ]
6-
7-
name: R-CMD-check
8-
9-
jobs:
10-
R-CMD-check:
11-
runs-on: macOS-latest
12-
steps:
13-
- uses: actions/checkout@v3
14-
- uses: r-lib/actions/setup-r@v2
15-
- name: Setting up pandoc for Rmd docs
16-
uses: r-lib/actions/setup-pandoc@v2
17-
- uses: r-lib/actions/setup-tinytex@v2
18-
- name: Install dependencies
19-
run: |
20-
install.packages(c("remotes", "rcmdcheck"))
21-
remotes::install_deps(dependencies = TRUE)
22-
shell: Rscript {0}
23-
- name: Check
24-
run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error")
25-
shell: Rscript {0}
1+
on:
2+
push:
3+
branches: [ master ]
4+
pull_request:
5+
branches: [ master ]
6+
7+
name: R-CMD-check
8+
9+
jobs:
10+
R-CMD-check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: r-lib/actions/setup-r@v2
15+
- name: Setting up pandoc for Rmd docs
16+
uses: r-lib/actions/setup-pandoc@v2
17+
- uses: r-lib/actions/setup-tinytex@v2
18+
- name: Install dependencies
19+
run: |
20+
install.packages(c("remotes", "rcmdcheck", "covr"))
21+
remotes::install_deps(dependencies = TRUE)
22+
shell: Rscript {0}
23+
24+
- name: Check
25+
run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error")
26+
shell: Rscript {0}
27+
28+
- name: Test coverage
29+
run: covr::codecov()
30+
shell: Rscript {0}
31+
env:
32+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ vignettes/tutorial_1.R
1010
vignettes/tutorial_1.html
1111
vignettes/tutorial_2.R
1212
vignettes/tutorial_2.html
13+
/doc/
14+
/Meta/

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-7
5-
Date: 2025-08-01
4+
Version: 3.2-0
5+
Date: 2025-08-15
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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
# version 3.2.0
2+
* Added two new methods, L1 and L2 distances, to the `cv_similarity` function
3+
* Fixed a warning in `cv_similarity` for colour aesthetics with ggplot
4+
* Fixed the summary method and plotting for `cv_spatial_autocor`
5+
16
# version 3.1.7
2-
* Temporarily added `sp` package dependency to avoid CRAN check as required by `automap` package [#55].
7+
* Temporarily added `sp` package dependency to avoid CRAN error as required by `automap` package [#55].
38

49
# version 3.1.6
510
* Resolved unclear error messages; issue [#52](https://github.com/rvalavi/blockCV/issues/52) by A. Márcia Barbosa
611
* Resolved ggplot testing failure; issue [#54](https://github.com/rvalavi/blockCV/issues/54) by Teun van den Brand
712

813
# version 3.1.5
9-
* Resolved background pattern artifacts in raster plotting; issue [#50](https://github.com/rvalavi/blockCV/issues/50) by Camila Neder.
14+
* Resolved background pattern artefacts in raster plotting; issue [#50](https://github.com/rvalavi/blockCV/issues/50) by Camila Neder.
1015

1116
# version 3.1.4
1217
* Just the `biomod2` example is updated in vignettes; and the link in help file
@@ -40,7 +45,7 @@
4045
* Massive performance improvement in the C++ code of `cv_nndm` function for large datasets
4146

4247
# version 3.0
43-
* Dependency to rgdal and rgeos are removed, and overall less dependency
48+
* Dependency to `rgdal` and `rgeos` are removed, and overall less dependency
4449
* Function names have been changed, with all functions now starting with `cv_`
4550
* The old functions (v2.x) still work to allow appropriate time for adapting the new code
4651
* The CV blocking functions are now: `cv_spatial`, `cv_cluster`, `cv_buffer`, and `cv_nndm`

R/RcppExports.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ nndm_cpp <- function(X, Gij, phi, min_train) {
55
.Call(`_blockCV_nndm_cpp`, X, Gij, phi, min_train)
66
}
77

8+
similarity_cpp <- function(train_mat, test_mat, rand_mat, L1 = TRUE) {
9+
.Call(`_blockCV_similarity_cpp`, train_mat, test_mat, rand_mat, L1)
10+
}
11+

R/checks.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Author: Roozbeh Valavi
22
# contact: valavi.r@gmail.com
33
# Date : May 2023
4-
# Version 0.2
5-
# Licence GPL v3
4+
# Version 0.3
5+
6+
# check the object is a blockCV object
7+
.check_cv <- function(x) {
8+
is_cv <- inherits(x, c("cv_spatial", "cv_cluster", "cv_buffer", "cv_nndm"))
9+
if (!is_cv) stop("'cv' must be a blockCV cv_* object.")
10+
}
11+
612

713
# check points fall within the raster layer
814
.check_within <- function(x, r) {

R/cv_block_size.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ cv_block_size <- function(
108108
if(!is.null(x)){
109109
geom_x <- ggplot2::geom_sf(
110110
data = x,
111-
switch(!is.null(column), ggplot2::aes(colour = {{ column }}), NULL),
112-
# ggplot2::aes(colour = {{ switch(!is.null(column), column, NULL) }}),
111+
switch(!is.null(column), ggplot2::aes(colour = {{ column }})),
113112
inherit.aes = FALSE,
114113
alpha = 0.5
115114
)
@@ -158,7 +157,7 @@ cv_block_size <- function(
158157
fill = "orangered4",
159158
alpha = 0.04,
160159
size = 0.2) +
161-
switch(!is.null(x), geom_x, NULL) +
160+
switch(!is.null(x), geom_x) +
162161
ggplot2::ggtitle("Spatial blocks",
163162
subtitle=paste("Using",
164163
input$num,

R/cv_buffer.R

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ cv_buffer <- function(
117117
add_bg <- (presence_bg && add_bg)
118118

119119
if(progress) pb <- utils::txtProgressBar(min = 0, max = n, style = 3)
120-
fold_list <- lapply(x_1s, function(i, pbag = add_bg){
120+
fold_list <- lapply(x_1s, function(i, pbag = add_bg) {
121121
if(pbag){
122122
test_ids <- which(dmatrix[i, ] <= size)
123123
inside <- x[test_ids, column, drop = TRUE]
@@ -127,14 +127,13 @@ cv_buffer <- function(
127127
test_set <- i
128128
}
129129
if(progress) utils::setTxtProgressBar(pb, i)
130-
list(as.numeric(which(dmatrix[i, ] > size)),
131-
as.numeric(test_set))
132-
}
133-
)
130+
131+
list(as.numeric(which(dmatrix[i, ] > size)), as.numeric(test_set))
132+
})
134133

135134
# calculate train test table summary
136135
if(report){
137-
train_test_table <- .ttt(fold_list, x, column, n)
136+
train_test_table <- .table_summary(fold_list, x, column, n)
138137
print(summary(train_test_table)[c(1,4,6), ])
139138
}
140139

@@ -172,32 +171,3 @@ summary.cv_buffer <- function(object, ...){
172171
}
173172
}
174173

175-
176-
# count the train and test records
177-
.ttt <- function(fold_list, x, column, n){
178-
if(is.null(column)){
179-
tt_count <- base::data.frame(train = rep(0, n), test = 0)
180-
for(i in seq_len(n)){
181-
train_set <- fold_list[[i]][[1]]
182-
test_set <- fold_list[[i]][[2]]
183-
tt_count$train[i] <- length(train_set)
184-
tt_count$test[i] <- length(test_set)
185-
}
186-
} else{
187-
cl <- sort(unique(x[, column, drop = TRUE]))
188-
clen <- length(cl)
189-
.check_classes(clen, column) # column should be binary or categorical
190-
tt_count <- as.data.frame(matrix(0, nrow = n, ncol = clen * 2))
191-
names(tt_count) <- c(paste("train", cl, sep = "_"), paste("test", cl, sep = "_"))
192-
for(i in seq_len(n)){
193-
train_set <- fold_list[[i]][[1]]
194-
test_set <- fold_list[[i]][[2]]
195-
countrain <- table(x[train_set, column, drop = TRUE])
196-
countest <- table(x[test_set, column, drop = TRUE])
197-
tt_count[i, which(cl %in% names(countrain))] <- countrain
198-
tt_count[i, clen + which(cl %in% names(countest))] <- countest
199-
}
200-
}
201-
202-
return(tt_count)
203-
}

R/cv_cluster.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ cv_cluster <- function(
205205
final_objs <- list(
206206
folds_list = fold_list,
207207
folds_ids = fold_ids,
208-
biomod_table = switch(biomod2, as.matrix(biomod_table), NULL),
208+
biomod_table = switch(biomod2, as.matrix(biomod_table)),
209209
k = k,
210210
column = column,
211211
type = ifelse(is.null(r), "Spatial Cluster", "Environmental Cluster"),

R/cv_nndm.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ cv_nndm <- function(
186186
)
187187
# calculate train test table summary
188188
if(report){
189-
train_test_table <- .ttt(fold_list, x, column, n)
189+
train_test_table <- .table_summary(fold_list, x, column, n)
190190
print(summary(train_test_table)[c(1,4,6), ])
191191
}
192192

0 commit comments

Comments
 (0)