Skip to content

Commit

Permalink
Error fix
Browse files Browse the repository at this point in the history
- deprecated function tests
  • Loading branch information
sigmafelix committed Sep 9, 2024
1 parent 2b19b0d commit a9e6938
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 0.8
- Bumped version from 0.7.8 to 0.8.0: improving package coverage
- README.md: two mermaid plots are pre-generated as png files
- Internal `clip_*()` functions are removed
- Internal `clip_*()` functions and `vect_validate()` are removed
- `par_map_args()` is renamed to `par_convert_f()`


Expand Down
18 changes: 15 additions & 3 deletions R/scale_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,25 @@ par_multirasters <-
#' f2(x = 1, y = 2, z = -1, w = 10)
#' @export
par_convert_f <- function(fun, arg_map) {

# Create a new function with the mapped arguments
new_fun <- function(...) {
# Capture the arguments passed to the new function
args <- list(...)
args_in <- list(...)

# Initialize an empty list for mapped arguments
mapped_args <- list()

# Map the arguments to the original function's arguments
mapped_args <- setNames(args, arg_map[names(args)])
# Loop through each argument in args_in
for (arg_name in names(args_in)) {
if (arg_name %in% names(arg_map)) {
# If the argument name is in arg_map, map it
mapped_args[[arg_map[[arg_name]]]] <- args_in[[arg_name]]
} else {
# Otherwise, keep the original argument name
mapped_args[[arg_name]] <- args_in[[arg_name]]
}
}

# Call the original function with the mapped arguments
do.call(fun, mapped_args)
Expand Down
27 changes: 0 additions & 27 deletions tests/testthat/test-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -659,33 +659,6 @@ testthat::test_that(".check_vector with file path-SpatVector", {
})



# vect_validate ####
testthat::test_that("vect_validate repairs input vector data", {
withr::local_package("sf")
withr::local_package("terra")
withr::local_options(list(sf_use_s2 = FALSE))

input_sf <-
sf::st_as_sf(
data.frame(
wkt = sf::st_as_text(sf::st_polygon(
list(rbind(c(0, 0), c(1, 0), c(1, 1), c(0, 1), c(0, 0)))
))
),
wkt = "wkt"
)
testthat::expect_true(
sf::st_is_valid(chopin:::vect_validate(input_sf))
)

input_terra <- terra::vect(input_sf)
testthat::expect_true(
terra::is.valid(chopin:::vect_validate(input_terra))
)
})


# .intersect tests ####
testthat::test_that(
".intersect unifies different package objects and intersects", {
Expand Down
15 changes: 10 additions & 5 deletions tests/testthat/test-scale_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -1118,16 +1118,21 @@ testthat::test_that(


# par_map_args tests ####
testthat::test_that("par_map_args works", {
testthat::test_that("par_convert_f works", {
example_fun <- function(x, y, z = 1) {
return(c(x = x, y = y, z = z))
}

# Example usage of map_args_xy
testthat::expect_no_error(
result <-
par_map_args(fun = example_fun,
name_match = list(a = "x", b = "y"),
a = 10, b = 20, z = 5)
resultfoo <-
par_convert_f(
fun = example_fun,
arg_map = c(a = "x", b = "y")
)
)

testthat::expect_true(is.function(resultfoo))
result <- resultfoo(a = 10, b = 20, z = 5)
testthat::expect_true(is.vector(result))
})

0 comments on commit a9e6938

Please sign in to comment.