Skip to content

[BUG] unlist2d doesn't keep the sf class if the list contains sf objects #825

@MGousseff

Description

@MGousseff

First of all : thank you for this package. Really.

Not sure if a bug or a request, but as collapse is "class agnostic", I report it as a bug
Describe the bug
Using unlist2d to a list which contains sf objects unlists properly, bind the rows of all the sf objects contained in the list, but the resulting object is a dataframe.

Steps/Code to Reproduce

#Create an sf object
V1 <- 1:3
V2 <- letters[1:3]
V3 <- sqrt(V1)
V4 <- sqrt(as.complex(-V1))
L <- list(v1=V1, v2=V2, v3=V3, v4=V4)
DF <- as.data.frame(L)
pt1 <- st_point(c(1,3))
pt2 <- pt1 + 1
pt3 <- pt2 + 1
pt_sfc <- st_as_sfc(list(pt1, pt2, pt3))
st_geometry(DF)<-pt_sfc

#Create a list of sf objects (3 times the same, not important)
dfList<-list(DF1=DF, DF2=DF, DF3=DF)
concatDF<-unlist2d(dfList)
class(concatDF) #"data.frame" and not "sf"

Expected behavior
class(concatDF) should return "sf"

Additional context
I have noticed other times when functions from the package do not keep the "sf" class. Sometimes I still use collapse and re-coerce to sf after transformation, but sometimes as a lazy coder I fall back to using dplyr function and it makes me sad ;-)

I hope this doesn't come from an error on my side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions