Skip to content

Commit

Permalink
fixes #2378
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Apr 23, 2024
1 parent b8ff604 commit 80edf95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# version 1.0-17

* `st_sf()` no longer strips `tbl` or `tbl_df` class labels; #2378

* `st_layers()` returns an object of class `c("sf_layers", "data.frame")`, with a dedicated `print` method.

* when `dim` is not `XYZM`, `sf_as_sf.data.frame()` interprets a length 4 `coords` argument to specify the corners of a rectangular polygon; #2357
Expand Down
6 changes: 4 additions & 2 deletions R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,16 @@ st_sf = function(..., agr = NA_agr_, row.names,
if (missing(row.names))
row.names = seq_along(x[[sf_column]])

df = if (inherits(x, "tbl_df")) # no worries:
df = if (inherits(x, c("tbl_df", "tbl"))) # no worries:
x
else if (length(x) == 1) # ONLY one sfc
data.frame(row.names = row.names)
else if (!sfc_last && inherits(x, "data.frame"))
x
else if (sfc_last && inherits(x, "data.frame"))
x[-all_sfc_columns]
else if (inherits(x[[1]], c("tbl_df", "tbl")))
x[[1]]
else
cbind(data.frame(row.names = row.names),
as.data.frame(x[-all_sfc_columns],
Expand Down Expand Up @@ -429,7 +431,7 @@ print.sf = function(x, ..., n = getOption("sf_max_print", default = 10)) {
app = paste0(app, "\n", "Active geometry column: ", attr(x, "sf_column"))
print(st_geometry(x), n = 0, what = "Simple feature collection with", append = app)
if (n > 0) {
if (inherits(x, "tbl_df"))
if (inherits(x, c("tbl_df", "tbl")))
NextMethod()
else {
y <- x
Expand Down

0 comments on commit 80edf95

Please sign in to comment.