rbindlist messing up with bouding box of spatial `sf` objects
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the minimal reproducible example using geobr, sf, and data.table, then compare rbindlist(test_list, fill = TRUE) with base rbind(rr, rs). Trace how the spatial bounding-box attribute changes and use the waldo comparisons to verify that the resulting sf object preserves the expected bbox.
Written by the indexing model from the issue text.
Description
I've found that rbindlist{data.table} somehow changes the bouding box of spatial sf objects. This is related to issue #2273 here, and I've linked to issues on geobr and tmap packages as well.
Minimal reproducible example
devtools::install_github("ipeaGIT/geobr", subdir = "r-package")
library(geobr)
library(sf)
library(data.table)
library(waldo)
# download sf data
rr <- read_state(code_state = 'RR')
rs <- read_state(code_state = 'RS')
test_list <- list(rr, rs)
# row bind with rbindlist
t1_list <- data.table::rbindlist(test_list, fill = TRUE)
t1 <- sf::st_sf(t1_list)
plot(t1['code_state'])
# base row bind
t2 <- rbind(rr,rs)
plot(t2['code_state'])
# compare
waldo::compare(t1, t2)
> `class(old)`: "sf" "data.table" "data.frame"
> `class(new)`: "sf" "data.frame"
>
> `attr(old$geom, 'bbox')`: "((-64.82525,-1.580633),(-58.88688,5.271841))"
> `attr(new$geom, 'bbox')`: "((-64.82525,-33.75208),(-49.69146,5.271841))"
For some reason, though, this problem is fixed when I run a simple subset removing a row hat does not exist in the data.
t3 <- subset(t1, abbrev_state != "xx")
waldo::compare(t2, t3)
> `class(old)`: "sf" "data.frame"
> `class(new)`: "sf" "data.table" "data.frame"
sessionInfo()
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] waldo_0.4.0 data.table_1.14.2 sf_1.0-7 geobr_1.6.6
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8.3 rstudioapi_0.13 rematch2_2.1.2
[4] magrittr_2.0.2 units_0.8-0 tidyselect_1.1.2
[7] R6_2.5.1 rlang_1.0.2 fansi_1.0.2
[10] httr_1.4.2 dplyr_1.0.8 tools_4.1.1
[13] grid_4.1.1 utf8_1.2.2 KernSmooth_2.23-20
[16] cli_3.1.1 e1071_1.7-9 DBI_1.1.2
[19] ellipsis_0.3.2 class_7.3-19 assertthat_0.2.1
[22] tibble_3.1.6 lifecycle_1.0.1 crayon_1.5.0
[25] purrr_0.3.4 vctrs_0.3.8 curl_4.3.2
[28] glue_1.6.2 proxy_0.4-26 diffobj_0.3.5
[31] compiler_4.1.1 pillar_1.7.0 generics_0.1.2
[34] classInt_0.4-3 pkgconfig_2.0.3
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·