Skip to content

When using separate_wider_delim() function remove sf class and returns tibble #2359

Open
@benjaminhlina

Description

@benjaminhlina

When using separate_wider_delim() with a sf object, the function misbehaves and returns a tibble. If using separate() the class of the sf object is retained. The same issue was documented in issue tidyverse/tidyr#1495 but no reprex was provided. I had originally made the issue report on the {tidyr} repo, see tidyverse/tidyr#1498, but was recently informed that is likely due to an issues with {sf} not supporting these newer versions of separate_ functions. This is using v1.3.0 of {tidyr} and {sf} v1.0-15 and see reprex.

# load packages 
suppressPackageStartupMessages({
  library(crawl) # loaded for example sf object 
  library(sf) # load sf 
  library(tidyr) # load for separate functions  
})

# load harbour seal data 
data("harborSeal_sf")

# check out the sf object 
class(harborSeal_sf)
#> [1] "sf"         "data.frame"
# make up fake column to separate 

harborSeal_sf$fake <- "test_1"
# now use separate_wide_delim 

error <- harborSeal_sf |>
  separate_wider_delim(cols = fake, names = c("fake", "num"), delim = "_")
class(error)
#> [1] "tbl_df"     "tbl"        "data.frame"
# returns tibble not an sf object so it changes the object's class 

# if we use separate it keeps the objects class 
no_error <- harborSeal_sf |>
  separate(col = fake, into = c("fake", "num"), sep = "_")

class(no_error)
#> [1] "sf"         "data.frame"

Created on 2024-03-14 with reprex v2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions