Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in fwrite, set option dateTimeAs separately for date and time #1979

Open
franknarf1 opened this issue Jan 6, 2017 · 2 comments
Open

in fwrite, set option dateTimeAs separately for date and time #1979

franknarf1 opened this issue Jan 6, 2017 · 2 comments
Labels

Comments

@franknarf1
Copy link
Contributor

Perhaps some syntax like

fwrite(DT, dateTimeAs = c(date = "squash", time = "ISO", datetime = "epoch"))

with each of the three options having "ISO" by default if omitted.

This would also make syntax for custom formats possible, like dateTimeAs = c(time = "%H:%M"), which I would use, since that's the csv convention where I work.

@mattdowle mattdowle changed the title [Request] in fread, set option dateTimeAs separately for date and time [Request] in fwrite, set option dateTimeAs separately for date and time Jan 25, 2017
@mattdowle
Copy link
Member

Yes controlling the format per column like that is good idea and no problem.

Custom format is tricky to implement at C level that runs very fast, though. Full flexibility such as format() provides needs code inside it to navigate the format string. Doing that over and over again for each field is wasteful and one of the reasons fwrite is very fast.

Adding a small set (say less than 20) of specific custom formats would be ok. They would just be variations on a theme and easy to code in C. I'm thinking we should only allow sane ones which are ordered by descending datepart size; i.e., no American mm/dd/yyyy.

If that sounds ok .... can you or someone propose the list of formats to implement? They can still look like a custom format "%H:%M". If someone attempted "%M:%H" it would error that it wasn't in the predefined set. Do we need any formats that don't use : to separate timeparts and - to separate date parts?

What if you specify "%H:%M" but there are seconds present in the data - should it warn that you're losing precision? If no seconds are present, it could automatically drop the seconds. Like it already does with POSIXct and milliseconds.

@franknarf1
Copy link
Contributor Author

Thanks, that makes sense.

If that sounds ok .... can you or someone propose the list of formats to implement?

%H:%M is the only one that comes to mind for me and, browsing around, I don't see any other common date or time formats. Maybe folks on the mailing list would have others.

@jangorecki jangorecki changed the title [Request] in fwrite, set option dateTimeAs separately for date and time in fwrite, set option dateTimeAs separately for date and time Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants