markfairbanks / tidytable

Tidy interface to 'data.table'
https://markfairbanks.github.io/tidytable/
Other
450 stars 32 forks source link

New `separate.()` columns should be placed after the input column #478

Closed markfairbanks closed 2 years ago

markfairbanks commented 2 years ago
pacman::p_load(tidytable, tidyverse)

df <- tidytable(x = c("a", "a.b", "a.b", NA), y = 1:4)

df %>%
  separate.(x, into = c("c1", "c2"), remove = FALSE)
#> # A tidytable: 4 × 4
#>   x         y c1    c2   
#>   <chr> <int> <chr> <chr>
#> 1 a         1 a     <NA> 
#> 2 a.b       2 a     b    
#> 3 a.b       3 a     b    
#> 4 <NA>      4 <NA>  <NA>

df %>%
  tidyr::separate(x, into = c("c1", "c2"), remove = FALSE)
#> Warning: Expected 2 pieces. Missing pieces filled with `NA` in 1 rows [1].
#> # A tidytable: 4 × 4
#>   x     c1    c2        y
#>   <chr> <chr> <chr> <int>
#> 1 a     a     <NA>      1
#> 2 a.b   a     b         2
#> 3 a.b   a     b         3
#> 4 <NA>  <NA>  <NA>      4
markfairbanks commented 2 years ago

As I think about this - if the user needs to move the columns they can do that with relocate.().