Question
fread column with only NA values as POSIXct returns warning and a character column
Update: I have opened an issue for this: https://github.com/Rdatatable/data.table/issues/6208
I would like to read a column of a NA
values as POSIXct
using fread
.
I would expect this to work:
library(data.table)
fwrite(data.table(datetime = as.POSIXct(NA)), "test.csv")
fread("test.csv", colClasses = "POSIXct")
However, this gives the following warning:
Warning message:
Column 'datetime' was requested to be 'POSIXct' but fread encountered the following error:
character string is not in a standard unambiguous format
so the column has been left as type 'character'
In contrast using utils::write.csv
and utils::read.csv
this works:
write.csv(data.frame(datetime = as.POSIXct(NA)), "test.csv", row.names = FALSE)
read.csv("test.csv", colClasses = "POSIXct")
Is there a possible workaround?
I used data.table_1.15.4
.
4 60
4