Hi there,
I used readr::cols()
to explicitly define column specifications in readr::read_csv()
. As I progress with my project, new columns appear in new data files. Most of the time new column types are correctly guessed by the read_csv()
, but not always. Therefore, I want to add column types for new columns in the existing list.
I used spec()
to get the list of specifications and manually correct the column type when needed. Now I want to append the initial list with the new columns. In the documentation, I found this solution:
library(readr)
t1 <- cols(
col1 = col_double(),
col2 = col_double()
)
t2 <- cols(
col3 = col_double(),
col4 = col_double(),
col2 = col_double()
)
t3 <- t1
t3$cols <- c(t1$cols, t2$cols)
t3
#> cols(
#> col1 = col_double(),
#> col2 = col_double(),
#> col3 = col_double(),
#> col4 = col_double(),
#> col2 = col_double()
#> )
The problem is that now "col2" is duplicated. Is there a simple (non-manual) way to get rid of duplicated cols?