Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid converting date to idate in R data.table fwrite 1.9.7?

Tags:

r

data.table

Having installed data.table 1.9.7 in a windows machine, I have a data.table A where one of its columns is of Date type. I want to export A to a CSV file with fwrite but when I run

fwrite(A,file="out1.csv")

the Date column is transformed to IDate integer type. I need to keep the date format because this file will be used to a different application, not R. How can I not have the Date column transformed to IDate? My first attempt was to use

A[,theDate:=as.character(theDate)] 

but it takes about 1000 seconds in a 100M rows data.table. Is there a way to avoid this?

like image 548
VassilisGeorgiou Avatar asked May 20 '16 12:05

VassilisGeorgiou


1 Answers

This is now implemented and is fast. Please update to data.table v1.9.8+. You can control how dates are written with dateTimeAs="ISO"|"squash"|"epoch"|"write.csv". See the current version of fwrite's manual page here.

like image 182
Matt Dowle Avatar answered Sep 23 '22 02:09

Matt Dowle