Skip to content

Commit

Permalink
extract_at fix
Browse files Browse the repository at this point in the history
- Homogenizing column names that are different from settings in `terra::extract()` (e.g., coverage_fraction)
  • Loading branch information
sigmafelix committed Nov 3, 2024
1 parent 2d3903d commit 5600c8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 6 additions & 2 deletions R/processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ kernelfunction <-
bind = TRUE,
ID = TRUE
)
extracted$id_chopin <- y[[id]][extracted$ID]

extracted[[id]] <- y[[id]][extracted$ID]
extracted$ID <- NULL
names(extracted)[names(extracted) == "id_chopin"] <- id
names(extracted)[names(extracted) == "weight"] <- "coverage_fraction"
names(extracted)[names(extracted) %in% c("weight", "fraction")] <-
"coverage_fraction"
}

if (iskernel) {
Expand Down Expand Up @@ -437,6 +440,7 @@ setMethod(
y = NULL,
id = NULL,
func = "mean",
terra = FALSE,
extent = NULL,
radius = NULL,
out_class = "sf",
Expand Down
12 changes: 7 additions & 5 deletions tests/testthat/test-processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ testthat::test_that("extract_at -- character-SpatVector inputs", {

})

testthat::test_that("extract_at -- character-SpatVector inputs", {
testthat::test_that("extract_at -- character-SpatVector inputs, terra mode", {
withr::local_package("sf")
withr::local_package("terra")
withr::local_package("dplyr")
Expand All @@ -243,12 +243,13 @@ testthat::test_that("extract_at -- character-SpatVector inputs", {
terra = TRUE,
extent = NULL
)
testthat::expect_s3_class(ncexpoly, "data.frame")
testthat::expect_s4_class(ncexpoly, "SpatVector")

testthat::expect_warning(
testthat::expect_warning(
testthat::expect_message(
testthat::expect_message(
ext_re <-
chopin::extract_at(
ncelev,
nccnty,
Expand All @@ -268,7 +269,7 @@ testthat::test_that("extract_at -- character-SpatVector inputs", {
})


testthat::test_that("extract_at -- character-sf inputs", {
testthat::test_that("extract_at -- character-sf inputs, terra mode", {
withr::local_package("sf")
withr::local_package("terra")
withr::local_package("dplyr")
Expand All @@ -288,9 +289,10 @@ testthat::test_that("extract_at -- character-sf inputs", {
chopin::extract_at(
ncelev,
nccnty,
"FIPS"
"FIPS",
terra = TRUE
)
testthat::expect_s3_class(ncexpoly, "data.frame")
testthat::expect_s4_class(ncexpoly, "SpatVector")

testthat::expect_warning(
testthat::expect_warning(
Expand Down

0 comments on commit 5600c8e

Please sign in to comment.