Handle mix of sf and sp classes in filter_spatial()
- Dominant language
- R
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Tests in `tests/testthat/test-filter_spatial()` are not currently passing. To run them: `test(filter = "filter_spatial")`. Here are two key pieces of the output:
```
test-filter_spatial.R:31: error: Alameda County (sp)
no applicable method for 'st_transform' applied to an object of class "c('SpatialPolygonsDataFrame', 'SpatialPolygons', 'Spatial', 'SpatialPolygonsNULL', 'SpatialVector')"
Backtrace:
1. testthat::expect_success(...) tests/testthat/test-filter_spatial.R:31:2
2. mapview::mapview(test_tracts)
10. mapview::addFeatures(., ALA_county_WGS84, fill = FALSE, color = "red")
16. leafem::addFeatures(map = map, data = data, pane = pane, ...)
17. sf::st_transform(data, sf::st_crs(map@object[[1]]))
```
```
test-filter_spatial.R:76: error: Richmond CARE Impact Region
unable to find an inherited method for function 'proj4string' for signature '"sf"'
Backtrace:
1. testthat::expect_message(...) tests/testthat/test-filter_spatial.R:76:2
6. geotools::filter_spatial(spobj1, spobj2)
7. geotools::filter_spatial_sp(x, y, FUN = FUN, ..., verbose = verbose) R/filter_spatial.R:26:4
8. sp::proj4string(spobj2) R/filter_spatial.R:92:2
```
It might be necessary to either:
- Make `filter_spatial(spobj1, spobj2, ...)` an S4 method, so that it dispatches based on the class of _both_ `spobj1` and `spobj2`; or
- Retain it as an S3 method — dispatching only on the class of `spobj1` — but put some `if ... else` logic inside `filter_spatial()` to coerce the class of `spobj2` to the class of `spobj1`, before it dispatches to either `filter_spatial_sp()` or `filter_spatial_sf()`, either of which should expect both `spobj1` and `spobj2` to be of the same class.
Contributor guide
No contributing guide indexed for this repository
Research direction
Run `test(filter = "filter_spatial")` and read `tests/testthat/test-filter_spatial.R` alongside `R/filter_spatial.R`. Trace `filter_spatial()`, `filter_spatial_sp()`, and `filter_spatial_sf()` to determine how mixed `sp` and `sf` inputs should dispatch or be coerced. Done means the reported Alameda County and Richmond CARE Impact Region tests pass without the shown transformation or `proj4string` errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100