Open
Description
If you use separate_wider_*
on a data frame with row names, the resulting data frame won't have row names anymore. Since documentation states that rows are not affected by this function, I suppose that this is an unwanted behavior.
library(tidyverse)
df <- data.frame(
row.names = letters[1:3],
col_to_separate = paste(LETTERS[1:3], LETTERS[1:3], sep = "-")
)
df
#> col_to_separate
#> a A-A
#> b B-B
#> c C-C
df %>%
separate_wider_delim(
col_to_separate,
delim = "-",
names = paste0("C", 1:2)
)
#> # A tibble: 3 × 2
#> C1 C2
#> <chr> <chr>
#> 1 A A
#> 2 B B
#> 3 C C
df %>%
separate_wider_position(
col_to_separate,
widths = c(C1 = 1, 1, C2 = 1)
)
#> # A tibble: 3 × 2
#> C1 C2
#> <chr> <chr>
#> 1 A A
#> 2 B B
#> 3 C C
df %>%
separate_wider_regex(
col_to_separate,
patterns = c(C1 = ".", ".", C2 = ".")
)
#> # A tibble: 3 × 2
#> C1 C2
#> <chr> <chr>
#> 1 A A
#> 2 B B
#> 3 C C
Created on 2023-05-24 with reprex v2.0.2