Closed faridcher closed 7 years ago
My approach is to use st_set_geometry(x, NULL)
, but I really like your function. Maybe it should be called st_drop_geometry
?
st_drop_geometry <- function(x) {
if(inherits(x,"sf")) {
x <- st_set_geometry(x, NULL)
class(x) <- 'data.frame'
}
return(x)
}
also works. The call is by @edzer .
As I've expressed earlier, the benefit of convenience here does not weight against the cost of the more complex API. An option might be to add this function as an example to the help page of sf
, so users who really fancy this can add it to their own scripts.
To convert sf objects to tables without geometry columns, I've been using:
simple_feature %>% as_tibble() %>% dplyr::select(-geometry)
Functions requiring tables can be chained in the middle of the pipe, and the output converted back to an sf object, e.g.
simple_feature %>% as_tibble() %>% .[!duplicated(.[, "Camera_Site"]),] %>% st_as_sf()
there are so many popular functions in r that don't support list column yet. I find myself repeatedly having to remove the geometry column of a sf object . so a simple function like this would be very useful:
which could be used as:
This function could also be used in
sf::as.data.frame.sf()
context to convert sf object to "pure" data.frame (i.e. without a list column).thanks