diff --git a/.Rbuildignore b/.Rbuildignore index 849c555..498bcf2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -15,3 +15,5 @@ ^vignettes/articles$ ^CRAN-SUBMISSION$ ^revdep$ +^[.]?air[.]toml$ +^\.vscode$ diff --git a/.github/workflows/format-check.yaml b/.github/workflows/format-check.yaml new file mode 100644 index 0000000..e29e3c4 --- /dev/null +++ b/.github/workflows/format-check.yaml @@ -0,0 +1,23 @@ +# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples + +on: + push: + branches: [main, master] + pull_request: + +name: format-check.yaml + +permissions: read-all + +jobs: + format-check: + name: format-check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install + uses: posit-dev/setup-air@v1 + + - name: Check + run: air format . --check diff --git a/.github/workflows/format-suggest.yaml b/.github/workflows/format-suggest.yaml new file mode 100644 index 0000000..8c4f117 --- /dev/null +++ b/.github/workflows/format-suggest.yaml @@ -0,0 +1,46 @@ +# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples + +on: + # Using `pull_request_target` over `pull_request` for elevated `GITHUB_TOKEN` + # privileges, otherwise we can't set `pull-requests: write` when the pull + # request comes from a fork, which is our main use case (external contributors). + # + # `pull_request_target` runs in the context of the target branch (`main`, usually), + # rather than in the context of the pull request like `pull_request` does. Due + # to this, we must explicitly checkout `ref: ${{ github.event.pull_request.head.sha }}`. + # This is typically frowned upon by GitHub, as it exposes you to potentially running + # untrusted code in a context where you have elevated privileges, but they explicitly + # call out the use case of reformatting and committing back / commenting on the PR + # as a situation that should be safe (because we aren't actually running the untrusted + # code, we are just treating it as passive data). + # https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ + pull_request_target: + +name: format-suggest.yaml + +jobs: + format-suggest: + name: format-suggest + runs-on: ubuntu-latest + + permissions: + # Required to push suggestion comments to the PR + pull-requests: write + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install + uses: posit-dev/setup-air@v1 + + - name: Format + run: air format . + + - name: Suggest + uses: reviewdog/action-suggester@v1 + with: + level: error + fail_level: error + tool_name: air diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..344f76e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "Posit.air-vscode" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a9f69fe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "[r]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "Posit.air-vscode" + }, + "[quarto]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "quarto.quarto" + } +} diff --git a/R/autoplot.R b/R/autoplot.R index 5e1ca0c..b049a85 100644 --- a/R/autoplot.R +++ b/R/autoplot.R @@ -64,10 +64,11 @@ autoplot.spatial_rset <- function(object, ..., alpha = 0.6) { mapping = ggplot2::aes(color = .fold., fill = .fold.) ) p <- p + ggplot2::geom_sf(..., alpha = alpha) - p <- p + ggplot2::guides( - colour = ggplot2::guide_legend("Fold"), - fill = ggplot2::guide_legend("Fold") - ) + p <- p + + ggplot2::guides( + colour = ggplot2::guide_legend("Fold"), + fill = ggplot2::guide_legend("Fold") + ) if (sum(bool_id_columns) == 2) { p <- p + ggplot2::facet_wrap(ggplot2::vars(.facet.)) @@ -97,10 +98,11 @@ autoplot.spatial_rsplit <- function(object, ..., alpha = 0.6) { data = object, mapping = ggplot2::aes(color = .class., fill = .class.) ) - p <- p + ggplot2::guides( - colour = ggplot2::guide_legend("Class"), - fill = ggplot2::guide_legend("Class") - ) + p <- p + + ggplot2::guides( + colour = ggplot2::guide_legend("Class"), + fill = ggplot2::guide_legend("Class") + ) p <- p + ggplot2::geom_sf(..., alpha = alpha) p + ggplot2::coord_sf() } @@ -109,7 +111,12 @@ autoplot.spatial_rsplit <- function(object, ..., alpha = 0.6) { #' @param show_grid When plotting [spatial_block_cv] objects, should the grid #' itself be drawn on top of the data? Set to FALSE to remove the grid. #' @export -autoplot.spatial_block_cv <- function(object, show_grid = TRUE, ..., alpha = 0.6) { +autoplot.spatial_block_cv <- function( + object, + show_grid = TRUE, + ..., + alpha = 0.6 +) { p <- autoplot.spatial_rset(object, ..., alpha = alpha) if (!show_grid) { diff --git a/R/buffer.R b/R/buffer.R index 99aa44c..fa1a45d 100644 --- a/R/buffer.R +++ b/R/buffer.R @@ -10,7 +10,13 @@ #' or assessment set. If `NULL`, no buffer is applied. #' #' @keywords internal -buffer_indices <- function(data, indices, radius, buffer, call = rlang::caller_env()) { +buffer_indices <- function( + data, + indices, + radius, + buffer, + call = rlang::caller_env() +) { standard_checks(data, "Buffering", call) n <- nrow(data) @@ -30,15 +36,21 @@ buffer_indices <- function(data, indices, radius, buffer, call = rlang::caller_e run_radius <- !is.null(radius) if (run_radius && units::set_units(radius, NULL) > 0) { # In case `radius` has no units, assume it's in the same units as `data` - if (!identical(sf::st_crs(data), sf::NA_crs_)) units(radius) <- units(distmat) + if (!identical(sf::st_crs(data), sf::NA_crs_)) { + units(radius) <- units(distmat) + } indices <- row_ids_within_dist(distmat, indices, radius) } # `buffer_indices` are _always_ needed # so re-code a NULL buffer as a 0, which will buffer nothing - if (is.null(buffer)) buffer <- 0L + if (is.null(buffer)) { + buffer <- 0L + } # In case `buffer` has no units, assume it's in the same units as `data` - if (!identical(sf::st_crs(data), sf::NA_crs_)) units(buffer) <- units(distmat) + if (!identical(sf::st_crs(data), sf::NA_crs_)) { + units(buffer) <- units(distmat) + } buffer_indices <- row_ids_within_dist(distmat, indices, buffer) purrr::map2(indices, buffer_indices, buffered_complement, n = n) diff --git a/R/checks.R b/R/checks.R index ecee3b5..b82a8ae 100644 --- a/R/checks.R +++ b/R/checks.R @@ -14,7 +14,9 @@ check_s2 <- function(data, calling_function, call = rlang::caller_env()) { if (is_longlat(data) && !sf::sf_use_s2()) { rlang::abort( c( - glue::glue("{calling_function} can only process geographic coordinates when using the s2 geometry library."), + glue::glue( + "{calling_function} can only process geographic coordinates when using the s2 geometry library." + ), "i" = "Reproject your data into a projected coordinate reference system using `sf::st_transform()`.", "i" = "Or install the `s2` package and enable it using `sf::sf_use_s2(TRUE)`." ), @@ -27,16 +29,24 @@ check_na_crs <- function(data, calling_function, call = rlang::caller_env()) { if (sf::st_crs(data) == sf::NA_crs_) { rlang::warn( c( - glue::glue("{calling_function} expects your data to have an appropriate coordinate reference system (CRS)."), + glue::glue( + "{calling_function} expects your data to have an appropriate coordinate reference system (CRS)." + ), i = "If possible, try setting a CRS using `sf::st_set_crs()`.", - i = glue::glue("Otherwise, {tolower(calling_function)} will assume your data is in projected coordinates.") + i = glue::glue( + "Otherwise, {tolower(calling_function)} will assume your data is in projected coordinates." + ) ), call = call ) } } -standard_checks <- function(data, calling_function, call = rlang::caller_env()) { +standard_checks <- function( + data, + calling_function, + call = rlang::caller_env() +) { check_sf(data, calling_function, call) check_na_crs(data, calling_function, call) check_s2(data, calling_function, call) @@ -47,12 +57,16 @@ standard_checks <- function(data, calling_function, call = rlang::caller_env()) #' @param v The number of partitions for the resampling. Set to `NULL` or `Inf` #' for the maximum sensible value (for leave-one-X-out cross-validation). #' @keywords internal -check_v <- function(v, - max_v, - objects, - allow_max_v = TRUE, - call = rlang::caller_env()) { - if (is.null(v)) v <- Inf +check_v <- function( + v, + max_v, + objects, + allow_max_v = TRUE, + call = rlang::caller_env() +) { + if (is.null(v)) { + v <- Inf + } if (!rlang::is_integerish(v) || length(v) != 1 || v < 1) { rlang::abort("`v` must be a single positive integer.", call = call) diff --git a/R/compat-vctrs-helpers.R b/R/compat-vctrs-helpers.R index ea02d9b..1ca5a45 100644 --- a/R/compat-vctrs-helpers.R +++ b/R/compat-vctrs-helpers.R @@ -14,11 +14,21 @@ delayedAssign("rset_subclasses", { withr::with_seed( 123, list( - spatial_block_cv = spatial_block_cv(test_data()), - spatial_clustering_cv = spatial_clustering_cv(test_data()), - spatial_buffer_vfold_cv = spatial_buffer_vfold_cv(test_data(), radius = 1, buffer = 1), - spatial_leave_location_out_cv = spatial_leave_location_out_cv(test_data(), idx), - spatial_nndm_cv = spatial_nndm_cv(test_data()[1:500, ], test_data()[501:682, ]) + spatial_block_cv = spatial_block_cv(test_data()), + spatial_clustering_cv = spatial_clustering_cv(test_data()), + spatial_buffer_vfold_cv = spatial_buffer_vfold_cv( + test_data(), + radius = 1, + buffer = 1 + ), + spatial_leave_location_out_cv = spatial_leave_location_out_cv( + test_data(), + idx + ), + spatial_nndm_cv = spatial_nndm_cv( + test_data()[1:500, ], + test_data()[501:682, ] + ) ) ) } else { diff --git a/R/compat-vctrs.R b/R/compat-vctrs.R index fe36635..31e3097 100644 --- a/R/compat-vctrs.R +++ b/R/compat-vctrs.R @@ -5,7 +5,13 @@ stop_incompatible_cast_rset <- function(x, to, ..., x_arg, to_arg) { details <- "Can't cast to an rset because attributes are likely incompatible." - vctrs::stop_incompatible_cast(x, to, x_arg = x_arg, to_arg = to_arg, details = details) + vctrs::stop_incompatible_cast( + x, + to, + x_arg = x_arg, + to_arg = to_arg, + details = details + ) } stop_never_called <- function(fn) { diff --git a/R/labels.R b/R/labels.R index 690001b..44a3313 100644 --- a/R/labels.R +++ b/R/labels.R @@ -8,11 +8,14 @@ pretty.spatial_clustering_cv <- function(x, ...) { #' @export print.spatial_clustering_cv <- function(x, ...) { cat("# ", pretty(x), "\n") - class(x) <- class(x)[!(class(x) %in% c( - "spatial_clustering_cv", - "spatial_rset", - "rset" - ))] + class(x) <- class(x)[ + !(class(x) %in% + c( + "spatial_clustering_cv", + "spatial_rset", + "rset" + )) + ] print(x, ...) } @@ -26,11 +29,14 @@ pretty.spatial_block_cv <- function(x, ...) { #' @export print.spatial_block_cv <- function(x, ...) { cat("# ", pretty(x), "\n") - class(x) <- class(x)[!(class(x) %in% c( - "spatial_block_cv", - "spatial_rset", - "rset" - ))] + class(x) <- class(x)[ + !(class(x) %in% + c( + "spatial_block_cv", + "spatial_rset", + "rset" + )) + ] print(x, ...) } @@ -44,11 +50,14 @@ pretty.spatial_leave_location_out_cv <- function(x, ...) { #' @export print.spatial_leave_location_out_cv <- function(x, ...) { cat("# ", pretty(x), "\n") - class(x) <- class(x)[!(class(x) %in% c( - "spatial_leave_location_out_cv", - "spatial_rset", - "rset" - ))] + class(x) <- class(x)[ + !(class(x) %in% + c( + "spatial_leave_location_out_cv", + "spatial_rset", + "rset" + )) + ] print(x, ...) } @@ -62,10 +71,13 @@ pretty.spatial_buffer_vfold_cv <- function(x, ...) { #' @export print.spatial_buffer_vfold_cv <- function(x, ...) { cat("# ", pretty(x), "\n") - class(x) <- class(x)[!(class(x) %in% c( - "spatial_buffer_vfold_cv", - "spatial_rset", - "rset" - ))] + class(x) <- class(x)[ + !(class(x) %in% + c( + "spatial_buffer_vfold_cv", + "spatial_rset", + "rset" + )) + ] print(x, ...) } diff --git a/R/misc.R b/R/misc.R index 006c36e..1cd0cec 100644 --- a/R/misc.R +++ b/R/misc.R @@ -27,7 +27,9 @@ split_unnamed <- function(x, f) { ## This will remove the assessment indices from an rsplit object rm_out <- function(x, buffer = NULL) { - if (is.null(buffer)) x$out_id <- NA + if (is.null(buffer)) { + x$out_id <- NA + } x } diff --git a/R/spatial_block_cv.R b/R/spatial_block_cv.R index 30a9007..0937ce7 100644 --- a/R/spatial_block_cv.R +++ b/R/spatial_block_cv.R @@ -61,15 +61,17 @@ #' Ecography 40(8), pp. 913-929, doi: 10.1111/ecog.02881. #' #' @export -spatial_block_cv <- function(data, - method = c("random", "snake", "continuous"), - v = 10, - relevant_only = TRUE, - radius = NULL, - buffer = NULL, - ..., - repeats = 1, - expand_bbox = 0.00001) { +spatial_block_cv <- function( + data, + method = c("random", "snake", "continuous"), + v = 10, + relevant_only = TRUE, + radius = NULL, + buffer = NULL, + ..., + repeats = 1, + expand_bbox = 0.00001 +) { method <- rlang::arg_match(method) if (method != "random" && repeats != 1) { @@ -103,7 +105,8 @@ spatial_block_cv <- function(data, original_number_of_blocks <- length(grid_blocks) block_fun <- function(method) { - switch(method, + switch( + method, "random" = random_block_cv( data, centroids, @@ -140,7 +143,8 @@ spatial_block_cv <- function(data, } } - percent_used <- split_objs$filtered_number_of_blocks[[1]] / original_number_of_blocks + percent_used <- split_objs$filtered_number_of_blocks[[1]] / + original_number_of_blocks if (percent_used < 0.1) { percent_used <- round(percent_used * 100, 2) @@ -186,12 +190,14 @@ expand_grid <- function(grid_box, expansion = 0.00001) { grid_box } -random_block_cv <- function(data, - centroids, - grid_blocks, - v, - radius = NULL, - buffer = NULL) { +random_block_cv <- function( + data, + centroids, + grid_blocks, + v, + radius = NULL, + buffer = NULL +) { n <- length(centroids) grid_blocks <- filter_grid_blocks(grid_blocks, centroids) @@ -205,35 +211,45 @@ random_block_cv <- function(data, generate_folds_from_blocks(data, centroids, grid_blocks, v, n, radius, buffer) } -systematic_block_cv <- function(data, - centroids, - grid_blocks, - v, - ordering = c("snake", "continuous"), - relevant_only = TRUE, - radius = NULL, - buffer = NULL) { +systematic_block_cv <- function( + data, + centroids, + grid_blocks, + v, + ordering = c("snake", "continuous"), + relevant_only = TRUE, + radius = NULL, + buffer = NULL +) { n <- length(centroids) ordering <- rlang::arg_match(ordering) - if (relevant_only) grid_blocks <- filter_grid_blocks(grid_blocks, centroids) + if (relevant_only) { + grid_blocks <- filter_grid_blocks(grid_blocks, centroids) + } n_blocks <- length(grid_blocks) v <- check_v(v, n_blocks, "blocks", call = rlang::caller_env(2)) folds <- rep(seq_len(v), length.out = length(grid_blocks)) - if (ordering == "snake") folds <- make_snake_ordering(folds, grid_blocks) + if (ordering == "snake") { + folds <- make_snake_ordering(folds, grid_blocks) + } grid_blocks <- sf::st_as_sf(grid_blocks) grid_blocks$fold <- folds - if (!relevant_only) grid_blocks <- filter_grid_blocks(grid_blocks, centroids) + if (!relevant_only) { + grid_blocks <- filter_grid_blocks(grid_blocks, centroids) + } num_folds <- length(unique(grid_blocks$fold)) if (num_folds != v) { rlang::warn(c( "Not all folds contained blocks with data:", - x = glue::glue("{v} folds were requested, \\ - but only {num_folds} contain any data."), + x = glue::glue( + "{v} folds were requested, \\ + but only {num_folds} contain any data." + ), x = "Empty folds were dropped.", i = "To avoid this, set `relevant_only = TRUE`." )) @@ -243,7 +259,15 @@ systematic_block_cv <- function(data, generate_folds_from_blocks(data, centroids, grid_blocks, v, n, radius, buffer) } -generate_folds_from_blocks <- function(data, centroids, grid_blocks, v, n, radius, buffer) { +generate_folds_from_blocks <- function( + data, + centroids, + grid_blocks, + v, + n, + radius, + buffer +) { filtered_number_of_blocks <- nrow(grid_blocks) grid_blocks <- split_unnamed(grid_blocks, grid_blocks$fold) diff --git a/R/spatial_clustering_cv.R b/R/spatial_clustering_cv.R index a1a587a..e7e7e33 100644 --- a/R/spatial_clustering_cv.R +++ b/R/spatial_clustering_cv.R @@ -82,14 +82,16 @@ #' #' @rdname spatial_clustering_cv #' @export -spatial_clustering_cv <- function(data, - v = 10, - cluster_function = c("kmeans", "hclust"), - radius = NULL, - buffer = NULL, - ..., - repeats = 1, - distance_function = function(x) as.dist(sf::st_distance(x))) { +spatial_clustering_cv <- function( + data, + v = 10, + cluster_function = c("kmeans", "hclust"), + radius = NULL, + buffer = NULL, + ..., + repeats = 1, + distance_function = function(x) as.dist(sf::st_distance(x)) +) { if (!rlang::is_function(cluster_function)) { cluster_function <- rlang::arg_match(cluster_function) } diff --git a/R/spatial_nndm_cv.R b/R/spatial_nndm_cv.R index fad578f..5b512d8 100644 --- a/R/spatial_nndm_cv.R +++ b/R/spatial_nndm_cv.R @@ -63,10 +63,14 @@ #' spatial_nndm_cv(ames_sf[1:100, ], ames_sf[2001:2100, ]) #' #' @export -spatial_nndm_cv <- function(data, prediction_sites, ..., - autocorrelation_range = NULL, - prediction_sample_size = 1000, - min_analysis_proportion = 0.5) { +spatial_nndm_cv <- function( + data, + prediction_sites, + ..., + autocorrelation_range = NULL, + prediction_sample_size = 1000, + min_analysis_proportion = 0.5 +) { # Data validation: check that all dots are used, # that data and prediction_sites are sf objects, # that data has a CRS and s2 is enabled if necessary @@ -120,10 +124,8 @@ spatial_nndm_cv <- function(data, prediction_sites, ..., pred_geometry <- unique(sf::st_geometry_type(prediction_sites)) use_provided_points <- length(pred_geometry) == 1 && pred_geometry == "POINT" - sample_provided_poly <- length(pred_geometry) == 1 && pred_geometry %in% c( - "POLYGON", - "MULTIPOLYGON" - ) + sample_provided_poly <- length(pred_geometry) == 1 && + pred_geometry %in% c("POLYGON", "MULTIPOLYGON") if (use_provided_points) { prediction_sites <- prediction_sites @@ -221,11 +223,13 @@ spatial_nndm_cv <- function(data, prediction_sites, ..., # How much data remains in analysis sets? prop_remaining <- sum( !is.na(distance_matrix[current_neighbor$row, ]) - ) / n_training - - if ((prop_close_training >= prop_close_prediction) & - (prop_remaining > min_analysis_proportion)) { + ) / + n_training + if ( + (prop_close_training >= prop_close_prediction) & + (prop_remaining > min_analysis_proportion) + ) { # Remove nearest neighbors from analysis sets until the % of points with # an NN in analysis at distance X in analysis ~= the % of points # in predict with NN in train at distance X @@ -287,10 +291,22 @@ spatial_nndm_cv <- function(data, prediction_sites, ..., ) } -find_next_neighbor <- function(current_neighbor, dist_to_nn_training, distance_matrix, equal_distance_ok = FALSE) { +find_next_neighbor <- function( + current_neighbor, + dist_to_nn_training, + distance_matrix, + equal_distance_ok = FALSE +) { operator <- if (equal_distance_ok) `>=` else `>` - current_neighbor$distance <- min(dist_to_nn_training[operator(dist_to_nn_training, current_neighbor$distance)]) - current_neighbor$row <- which(dist_to_nn_training == current_neighbor$distance)[1] - current_neighbor$col <- which(distance_matrix[current_neighbor$row, ] == current_neighbor$distance) + current_neighbor$distance <- min(dist_to_nn_training[operator( + dist_to_nn_training, + current_neighbor$distance + )]) + current_neighbor$row <- which( + dist_to_nn_training == current_neighbor$distance + )[1] + current_neighbor$col <- which( + distance_matrix[current_neighbor$row, ] == current_neighbor$distance + ) current_neighbor } diff --git a/R/spatial_vfold_cv.R b/R/spatial_vfold_cv.R index c029131..6d1863e 100644 --- a/R/spatial_vfold_cv.R +++ b/R/spatial_vfold_cv.R @@ -61,21 +61,25 @@ #' ames_neighborhoods <- spatial_leave_location_out_cv(ames_sf, Neighborhood) #' #' @export -spatial_buffer_vfold_cv <- function(data, - radius, - buffer, - v = 10, - repeats = 1, - strata = NULL, - breaks = 4, - pool = 0.1, - ...) { +spatial_buffer_vfold_cv <- function( + data, + radius, + buffer, + v = 10, + repeats = 1, + strata = NULL, + breaks = 4, + pool = 0.1, + ... +) { standard_checks(data, "`spatial_buffer_vfold_cv()`") if (missing(radius) || missing(buffer)) { use_vfold <- NULL if (missing(radius) && missing(buffer)) { - use_vfold <- c(i = "Or use `rsample::vfold_cv() to use a non-spatial V-fold.") + use_vfold <- c( + i = "Or use `rsample::vfold_cv() to use a non-spatial V-fold." + ) } rlang::abort( c( @@ -121,7 +125,9 @@ spatial_buffer_vfold_cv <- function(data, if (length(strata) == 0) strata <- NULL } - if (!is.null(strata)) names(strata) <- NULL + if (!is.null(strata)) { + names(strata) <- NULL + } cv_att <- list( v = v, repeats = repeats, @@ -159,13 +165,15 @@ spatial_buffer_vfold_cv <- function(data, #' @rdname spatial_vfold #' #' @export -spatial_leave_location_out_cv <- function(data, - group, - v = NULL, - radius = NULL, - buffer = NULL, - ..., - repeats = 1) { +spatial_leave_location_out_cv <- function( + data, + group, + v = NULL, + radius = NULL, + buffer = NULL, + ..., + repeats = 1 +) { if (!missing(group)) { group <- tidyselect::eval_select(rlang::enquo(group), data) } @@ -173,7 +181,9 @@ spatial_leave_location_out_cv <- function(data, if (missing(group) || length(group) == 0) { group <- NULL } else { - if (is.null(v)) v <- length(unique(data[[group]])) + if (is.null(v)) { + v <- length(unique(data[[group]])) + } v <- check_v(v, length(unique(data[[group]])), "locations") n <- nrow(data) if (v == n && repeats > 1) { @@ -223,15 +233,17 @@ spatial_leave_location_out_cv <- function(data, ) } -posthoc_buffer_rset <- function(data, - rset, - rsplit_class, - rset_class, - radius, - buffer, - n, - v, - cv_att) { +posthoc_buffer_rset <- function( + data, + rset, + rsplit_class, + rset_class, + radius, + buffer, + n, + v, + cv_att +) { # This basically undoes everything post-`split_unnamed` for us # so we're back to an unnamed list of assessment-set indices indices <- purrr::map(rset$splits, as.integer, "assessment") diff --git a/R/zzz-compat-vctrs-spatial_block_cv.R b/R/zzz-compat-vctrs-spatial_block_cv.R index 7e2d071..dea4ce4 100644 --- a/R/zzz-compat-vctrs-spatial_block_cv.R +++ b/R/zzz-compat-vctrs-spatial_block_cv.R @@ -58,23 +58,53 @@ vec_restore.spatial_block_cv <- function(x, to, ...) { # bootstraps object. #' @export -vec_ptype2.spatial_block_cv.spatial_block_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_block_cv.spatial_block_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_block_cv.spatial_block_cv") } #' @export -vec_ptype2.spatial_block_cv.tbl_df <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_block_cv.tbl_df <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_block_cv.tbl_df") } #' @export -vec_ptype2.tbl_df.spatial_block_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.tbl_df.spatial_block_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.tbl_df.spatial_block_cv") } #' @export -vec_ptype2.spatial_block_cv.data.frame <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_block_cv.data.frame <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_block_cv.data.frame") } #' @export -vec_ptype2.data.frame.spatial_block_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.data.frame.spatial_block_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.data.frame.spatial_block_cv") } @@ -90,22 +120,52 @@ vec_ptype2.data.frame.spatial_block_cv <- function(x, y, ..., x_arg = "", y_arg # with all of the data in `x` cast to the type of `to`. #' @export -vec_cast.spatial_block_cv.spatial_block_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_block_cv.spatial_block_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_block_cv.tbl_df <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_block_cv.tbl_df <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.tbl_df.spatial_block_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.tbl_df.spatial_block_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { tib_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_block_cv.data.frame <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_block_cv.data.frame <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.data.frame.spatial_block_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.data.frame.spatial_block_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } diff --git a/R/zzz-compat-vctrs-spatial_buffer_vfold_cv.R b/R/zzz-compat-vctrs-spatial_buffer_vfold_cv.R index dcc3b6b..a35d154 100644 --- a/R/zzz-compat-vctrs-spatial_buffer_vfold_cv.R +++ b/R/zzz-compat-vctrs-spatial_buffer_vfold_cv.R @@ -58,23 +58,55 @@ vec_restore.spatial_buffer_vfold_cv <- function(x, to, ...) { # bootstraps object. #' @export -vec_ptype2.spatial_buffer_vfold_cv.spatial_buffer_vfold_cv <- function(x, y, ..., x_arg = "", y_arg = "") { - stop_never_called("vec_ptype2.spatial_buffer_vfold_cv.spatial_buffer_vfold_cv") +vec_ptype2.spatial_buffer_vfold_cv.spatial_buffer_vfold_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { + stop_never_called( + "vec_ptype2.spatial_buffer_vfold_cv.spatial_buffer_vfold_cv" + ) } #' @export -vec_ptype2.spatial_buffer_vfold_cv.tbl_df <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_buffer_vfold_cv.tbl_df <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_buffer_vfold_cv.tbl_df") } #' @export -vec_ptype2.tbl_df.spatial_buffer_vfold_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.tbl_df.spatial_buffer_vfold_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.tbl_df.spatial_buffer_vfold_cv") } #' @export -vec_ptype2.spatial_buffer_vfold_cv.data.frame <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_buffer_vfold_cv.data.frame <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_buffer_vfold_cv.data.frame") } #' @export -vec_ptype2.data.frame.spatial_buffer_vfold_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.data.frame.spatial_buffer_vfold_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.data.frame.spatial_buffer_vfold_cv") } @@ -90,22 +122,52 @@ vec_ptype2.data.frame.spatial_buffer_vfold_cv <- function(x, y, ..., x_arg = "", # with all of the data in `x` cast to the type of `to`. #' @export -vec_cast.spatial_buffer_vfold_cv.spatial_buffer_vfold_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_buffer_vfold_cv.spatial_buffer_vfold_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_buffer_vfold_cv.tbl_df <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_buffer_vfold_cv.tbl_df <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.tbl_df.spatial_buffer_vfold_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.tbl_df.spatial_buffer_vfold_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { tib_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_buffer_vfold_cv.data.frame <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_buffer_vfold_cv.data.frame <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.data.frame.spatial_buffer_vfold_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.data.frame.spatial_buffer_vfold_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } diff --git a/R/zzz-compat-vctrs-spatial_clustering_cv.R b/R/zzz-compat-vctrs-spatial_clustering_cv.R index 6036fd9..d84cb0b 100644 --- a/R/zzz-compat-vctrs-spatial_clustering_cv.R +++ b/R/zzz-compat-vctrs-spatial_clustering_cv.R @@ -58,23 +58,53 @@ vec_restore.spatial_clustering_cv <- function(x, to, ...) { # bootstraps object. #' @export -vec_ptype2.spatial_clustering_cv.spatial_clustering_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_clustering_cv.spatial_clustering_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_clustering_cv.spatial_clustering_cv") } #' @export -vec_ptype2.spatial_clustering_cv.tbl_df <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_clustering_cv.tbl_df <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_clustering_cv.tbl_df") } #' @export -vec_ptype2.tbl_df.spatial_clustering_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.tbl_df.spatial_clustering_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.tbl_df.spatial_clustering_cv") } #' @export -vec_ptype2.spatial_clustering_cv.data.frame <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_clustering_cv.data.frame <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_clustering_cv.data.frame") } #' @export -vec_ptype2.data.frame.spatial_clustering_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.data.frame.spatial_clustering_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.data.frame.spatial_clustering_cv") } @@ -90,22 +120,52 @@ vec_ptype2.data.frame.spatial_clustering_cv <- function(x, y, ..., x_arg = "", y # with all of the data in `x` cast to the type of `to`. #' @export -vec_cast.spatial_clustering_cv.spatial_clustering_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_clustering_cv.spatial_clustering_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_clustering_cv.tbl_df <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_clustering_cv.tbl_df <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.tbl_df.spatial_clustering_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.tbl_df.spatial_clustering_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { tib_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_clustering_cv.data.frame <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_clustering_cv.data.frame <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.data.frame.spatial_clustering_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.data.frame.spatial_clustering_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } diff --git a/R/zzz-compat-vctrs-spatial_leave_location_out_cv.R b/R/zzz-compat-vctrs-spatial_leave_location_out_cv.R index 58e0019..4ed7d2b 100644 --- a/R/zzz-compat-vctrs-spatial_leave_location_out_cv.R +++ b/R/zzz-compat-vctrs-spatial_leave_location_out_cv.R @@ -58,23 +58,55 @@ vec_restore.spatial_leave_location_out_cv <- function(x, to, ...) { # bootstraps object. #' @export -vec_ptype2.spatial_leave_location_out_cv.spatial_leave_location_out_cv <- function(x, y, ..., x_arg = "", y_arg = "") { - stop_never_called("vec_ptype2.spatial_leave_location_out_cv.spatial_leave_location_out_cv") +vec_ptype2.spatial_leave_location_out_cv.spatial_leave_location_out_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { + stop_never_called( + "vec_ptype2.spatial_leave_location_out_cv.spatial_leave_location_out_cv" + ) } #' @export -vec_ptype2.spatial_leave_location_out_cv.tbl_df <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_leave_location_out_cv.tbl_df <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_leave_location_out_cv.tbl_df") } #' @export -vec_ptype2.tbl_df.spatial_leave_location_out_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.tbl_df.spatial_leave_location_out_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.tbl_df.spatial_leave_location_out_cv") } #' @export -vec_ptype2.spatial_leave_location_out_cv.data.frame <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_leave_location_out_cv.data.frame <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_leave_location_out_cv.data.frame") } #' @export -vec_ptype2.data.frame.spatial_leave_location_out_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.data.frame.spatial_leave_location_out_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.data.frame.spatial_leave_location_out_cv") } @@ -90,22 +122,52 @@ vec_ptype2.data.frame.spatial_leave_location_out_cv <- function(x, y, ..., x_arg # with all of the data in `x` cast to the type of `to`. #' @export -vec_cast.spatial_leave_location_out_cv.spatial_leave_location_out_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_leave_location_out_cv.spatial_leave_location_out_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_leave_location_out_cv.tbl_df <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_leave_location_out_cv.tbl_df <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.tbl_df.spatial_leave_location_out_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.tbl_df.spatial_leave_location_out_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { tib_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_leave_location_out_cv.data.frame <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_leave_location_out_cv.data.frame <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.data.frame.spatial_leave_location_out_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.data.frame.spatial_leave_location_out_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } diff --git a/R/zzz-compat-vctrs-spatial_nndm_cv.R b/R/zzz-compat-vctrs-spatial_nndm_cv.R index 92e04a6..467a49b 100644 --- a/R/zzz-compat-vctrs-spatial_nndm_cv.R +++ b/R/zzz-compat-vctrs-spatial_nndm_cv.R @@ -58,23 +58,53 @@ vec_restore.spatial_nndm_cv <- function(x, to, ...) { # bootstraps object. #' @export -vec_ptype2.spatial_nndm_cv.spatial_nndm_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_nndm_cv.spatial_nndm_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_nndm_cv.spatial_nndm_cv") } #' @export -vec_ptype2.spatial_nndm_cv.tbl_df <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_nndm_cv.tbl_df <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_nndm_cv.tbl_df") } #' @export -vec_ptype2.tbl_df.spatial_nndm_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.tbl_df.spatial_nndm_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.tbl_df.spatial_nndm_cv") } #' @export -vec_ptype2.spatial_nndm_cv.data.frame <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.spatial_nndm_cv.data.frame <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.spatial_nndm_cv.data.frame") } #' @export -vec_ptype2.data.frame.spatial_nndm_cv <- function(x, y, ..., x_arg = "", y_arg = "") { +vec_ptype2.data.frame.spatial_nndm_cv <- function( + x, + y, + ..., + x_arg = "", + y_arg = "" +) { stop_never_called("vec_ptype2.data.frame.spatial_nndm_cv") } @@ -90,22 +120,52 @@ vec_ptype2.data.frame.spatial_nndm_cv <- function(x, y, ..., x_arg = "", y_arg = # with all of the data in `x` cast to the type of `to`. #' @export -vec_cast.spatial_nndm_cv.spatial_nndm_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_nndm_cv.spatial_nndm_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_nndm_cv.tbl_df <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_nndm_cv.tbl_df <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.tbl_df.spatial_nndm_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.tbl_df.spatial_nndm_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { tib_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.spatial_nndm_cv.data.frame <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.spatial_nndm_cv.data.frame <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { stop_incompatible_cast_rset(x, to, x_arg = x_arg, to_arg = to_arg) } #' @export -vec_cast.data.frame.spatial_nndm_cv <- function(x, to, ..., x_arg = "", to_arg = "") { +vec_cast.data.frame.spatial_nndm_cv <- function( + x, + to, + ..., + x_arg = "", + to_arg = "" +) { df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } diff --git a/air.toml b/air.toml new file mode 100644 index 0000000..b2c21bf --- /dev/null +++ b/air.toml @@ -0,0 +1,2 @@ +[format] +exclude = ["inst/vctrs_template.R"] diff --git a/data-raw/boston_canopy.R b/data-raw/boston_canopy.R index 8a19759..8416e6f 100644 --- a/data-raw/boston_canopy.R +++ b/data-raw/boston_canopy.R @@ -1,6 +1,8 @@ ## code to prepare `boston_canopy` dataset goes here working_dir <- file.path(tempdir(), "boston_canopy") -if (!dir.exists(working_dir)) dir.create(working_dir) +if (!dir.exists(working_dir)) { + dir.create(working_dir) +} download.file( "https://bostonopendata-boston.opendata.arcgis.com/datasets/boston::hex-tree-canopy-change-metrics.zip?outSR=%7B%22latestWkid%22%3A2249%2C%22wkid%22%3A102686%7D", diff --git a/data/boston_canopy.R b/data/boston_canopy.R index 4472d57..c512e60 100644 --- a/data/boston_canopy.R +++ b/data/boston_canopy.R @@ -1,4 +1,7 @@ -delayedAssign("boston_canopy", local({ - requireNamespace("sf", quietly = TRUE) - spatialsample:::boston_canopy -})) +delayedAssign( + "boston_canopy", + local({ + requireNamespace("sf", quietly = TRUE) + spatialsample:::boston_canopy + }) +) diff --git a/tests/testthat/test-buffer.R b/tests/testthat/test-buffer.R index 4b1b4bb..262c2be 100644 --- a/tests/testthat/test-buffer.R +++ b/tests/testthat/test-buffer.R @@ -248,7 +248,6 @@ test_that("using buffers", { ) ) - # The default RNG changed in 3.6.0 skip_if_not(getRversion() >= numeric_version("3.6.0")) diff --git a/tests/testthat/test-compat-dplyr.R b/tests/testthat/test-compat-dplyr.R index c41724e..76791d6 100644 --- a/tests/testthat/test-compat-dplyr.R +++ b/tests/testthat/test-compat-dplyr.R @@ -132,7 +132,11 @@ test_that("summarise() always drops the rset class", { test_that("group_by() always returns a bare grouped-df or bare tibble", { for (x in rset_subclasses) { expect_s3_class_bare_tibble(group_by(x)) - expect_s3_class(group_by(x, splits), c("grouped_df", "tbl_df", "tbl", "data.frame"), exact = TRUE) + expect_s3_class( + group_by(x, splits), + c("grouped_df", "tbl_df", "tbl", "data.frame"), + exact = TRUE + ) } }) diff --git a/tests/testthat/test-spatial_block_cv.R b/tests/testthat/test-spatial_block_cv.R index 676f776..9e7d1cd 100644 --- a/tests/testthat/test-spatial_block_cv.R +++ b/tests/testthat/test-spatial_block_cv.R @@ -148,7 +148,8 @@ test_that("systematic assignment -- continuous", { expect_true(all(good_holdout)) set.seed(123) - rs3 <- spatial_block_cv(ames_sf, + rs3 <- spatial_block_cv( + ames_sf, method = "continuous", relevant_only = FALSE, v = 4 diff --git a/tests/testthat/test-spatial_nndm_cv.R b/tests/testthat/test-spatial_nndm_cv.R index aad44c8..f2e8328 100644 --- a/tests/testthat/test-spatial_nndm_cv.R +++ b/tests/testthat/test-spatial_nndm_cv.R @@ -11,7 +11,6 @@ Smithsonian_sf <- sf::st_as_sf( ) test_that("bad args", { - expect_snapshot( spatial_nndm_cv(Smithsonian_sf[1:15, ], Smithsonian[16:20, ]), error = TRUE @@ -97,7 +96,6 @@ test_that("can pass a single polygon to sample within", { }) - test_that("printing", { skip_if_not(sf::sf_use_s2()) # The default RNG changed in 3.6.0 @@ -120,7 +118,7 @@ test_that("passing a polygon works correctly", { skip_if_not(sf::sf_use_s2()) ames_sf <- sf::st_as_sf( modeldata::ames, - coords = c("Longitude", "Latitude"), + coords = c("Longitude", "Latitude"), crs = 4326 ) ch <- sf::st_as_sfc(sf::st_bbox(ames_sf)) @@ -136,4 +134,4 @@ test_that("passing a polygon works correctly", { nndm_2 <- spatial_nndm_cv(ames_sf[1:100, ], ch) ) expect_identical(nndm_1, nndm_2) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-spatial_vfold_cv.R b/tests/testthat/test-spatial_vfold_cv.R index e99380b..c6e1fe5 100644 --- a/tests/testthat/test-spatial_vfold_cv.R +++ b/tests/testthat/test-spatial_vfold_cv.R @@ -15,7 +15,11 @@ test_that("erroring when no S2", { error = TRUE ) expect_snapshot( - suppressMessages(spatial_leave_location_out_cv(ames_sf, Neighborhood, buffer = 500)), + suppressMessages(spatial_leave_location_out_cv( + ames_sf, + Neighborhood, + buffer = 500 + )), error = TRUE ) sf::sf_use_s2(s2_store) @@ -185,7 +189,12 @@ test_that("bad args", { set.seed(123) expect_snapshot( - spatial_buffer_vfold_cv(ames_sf, v = c(5, 10), buffer = NULL, radius = NULL), + spatial_buffer_vfold_cv( + ames_sf, + v = c(5, 10), + buffer = NULL, + radius = NULL + ), error = TRUE ) @@ -198,7 +207,12 @@ test_that("bad args", { set.seed(123) expect_snapshot( - spatial_buffer_vfold_cv(boston_canopy, v = 683, buffer = NULL, radius = NULL) + spatial_buffer_vfold_cv( + boston_canopy, + v = 683, + buffer = NULL, + radius = NULL + ) ) set.seed(123)