rvalavi / blockCV

The blockCV package creates spatially or environmentally separated training and testing folds for cross-validation to provide a robust error estimation in spatially structured environments. See
https://doi.org/10.1111/2041-210X.13107
GNU General Public License v3.0
107 stars 24 forks source link

`cv_spatial()` prints unnecessary empty line #31

Closed pat-s closed 1 year ago

pat-s commented 1 year ago

In https://github.com/rvalavi/blockCV/blob/master/R/cv_spatial.R#L407

This causes tests with expect_silent() to error as the function actually returns \n. The cat() should be conditioned under the report block to not always print an empty line and probably also only appear within the warning() calls itself and not be executed standalone.

You can verify this when creating a reprex and seeing an empty line appearing in the console before the prompter for the next command comes up:

ℹ Rendering reprex...
✔ Reprex output is on the clipboard.
> # hexagonal spatial blocking by specified size and random assignment
> sb1 <- cv_spatial(x = pa_data,
+                   column = "occ",
+                   size = 4500,
+                   k = 5,
+                   selection = "random",
+                   iteration = 50,
+                   progress = FALSE,
+                   report = FALSE,
+                   plot = FALSE)

> 
library(blockCV)
#> blockCV 3.0.0

# import presence-absence species data
points <- read.csv(system.file("extdata/", "species.csv", package = "blockCV"))
# make an sf object from data.frame
pa_data <- sf::st_as_sf(points, coords = c("x", "y"), crs = 7845)

# hexagonal spatial blocking by specified size and random assignment
sb1 <- cv_spatial(
  x = pa_data,
  column = "occ",
  size = 4500,
  k = 5,
  selection = "random",
  iteration = 50,
  progress = FALSE,
  report = FALSE
)

Created on 2023-02-28 with reprex v2.0.2

rvalavi commented 1 year ago

Thanks for the reports @pat-s. I'll check both issues over the weekend.

rvalavi commented 1 year ago

Solved!