I was wondering if there is a way to apply a cols() object to an existing data_frame instead of just when using read_csv.
For example, for several reasons I'm using fread() to read some data (mostly because of automatically detecting how many rows to skip when reading a csv). But down the line I'd rather use data_frame instead of data.table. And I want to make sure the file read has the correct column types, which is also saved somewhere.
So I want some function apply_col_types() that could work like this:
dt <- data.table(A = c('1','2','3',NA,'5'), B = rep('a',5)) # this would actually be coming from fread cl <- c('n', 'c') # this is also saved somewhere upstream df <- dt %>% as_data_frame() %>% apply_col_types(cl)
Does something like this exists?