I am trying to save and read a data.table using fread with yaml = TRUE. This should preserve the column types.
When I read the file using fread("filename", yaml = TRUE), numbers, factors and characters have the correct type, but the type "Date" is converted to "character".
Here is an example:
library(data.table)
dt <- data.table(date = as.POSIXct(c("2006-05-01", "2006-05-02")),
b = as.factor(c(1,2)),
c = c(3,4))
print(class(dt$date))
fwrite(dt, "dt.csv", yaml = TRUE)
dt <- fread("dt.csv", yaml = TRUE)
print(class(dt$date))
here is the csv file
Is it possible to preserve the "Date" type when reading the file ?