You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
st_as_sf used on a data.table creates an object with some broken functionality. While I wouldn't necessarily expect to be able to use data.table specific functions on the result, base functions appear to remain overridden by their data.table equivalent and are not functional until the user manually removes the data.table class. I'll provide an example with split.
To Reproduce
library(sf)
library(data.table)
# Make a data.table (some text borrowed from KeesDoolNMI in issue 1749)
df <- data.table(geom = rep("POLYGON ((6.215807 52.60666, 6.215807 52.60651, 6.215394 52.60651, 6.215394 52.60666, 6.215807 52.60666))", 10), group = rep(1:2, 5))
# Now set as sf data.frame
df <- st_as_sf(df, wkt = "geom")
# df has both data.table and sf classes
class(df)
#> [1] "sf" "data.table" "data.frame"
# This fails
df_split <- split(df, df$group)
#> Error in `[.data.frame`(x, i) : undefined columns selected
# But after casting back to data.frame, it works
data.table::setDF(df)
df_split <- split(df, df$group)
Describe the bug
st_as_sf
used on adata.table
creates an object with some broken functionality. While I wouldn't necessarily expect to be able to use data.table specific functions on the result, base functions appear to remain overridden by theirdata.table
equivalent and are not functional until the user manually removes thedata.table
class. I'll provide an example withsplit
.To Reproduce
If reporting a change from previous versions
✔️ Please read https://cran.r-project.org/web/packages/sf/news/news.html first.
The text was updated successfully, but these errors were encountered: