Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upInconsistent Treatment of dates #13
Comments
|
Thanks for the report. I concur that that should (ideally) not be happening. The easy part first. Once you quote them, TOML leaves them alone and just treats them as character. So they never become dates. That is what JSON, XML, ... and all other formats without native dates do. Next, single date. That works as expected. Leaving the vector / array of dates. That is actually a known issue in R as well. I.e. the following has been biting me a large number of times: R> dvec <- Sys.Date() + 0:2
R> dvec
[1] "2017-03-17" "2017-03-18" "2017-03-19"
R> for (d in dvec) print(d)
[1] 17242
[1] 17243
[1] 17244
R> I think we may just have the same thing happening here. |
|
I.e.: R> dvec
[1] "2017-03-17" "2017-03-18" "2017-03-19"
R> as.vector(dvec)
[1] 17242 17243 17244
R> |
|
This is a consequence of how
And "vector" refers to the "strict R" sense of the word. So, essentially, all attributes are ignored, including |
|
The same thing happens with Datetime. I.e. if I add
I get R> parseTOML("/tmp/datebug.toml")
List of 2
$ another:List of 2
..$ datetime : POSIXct[1:1], format: "2017-03-17 14:09:00"
..$ datetime_array: num [1:3] 1.49e+09 1.49e+09 1.49e+09
$ section:List of 4
..$ date : chr "2017-01-01"
..$ date_array : chr [1:3] "2017-01-01" "2017-01-01" "2017-01-01"
..$ date_array_unquoted: num [1:4] 16801 16801 16801 16801
..$ date_unqoted : Date[1:1], format: "2016-01-01"
R> But I don't think I have an easy fix. |
|
Yeah - why its happening makes sense. Apologies, I'm not too familiar with Rcpp, but when you're creating vectors, can you set attributes on them inside of Rcpp?
|
|
Nothing like some casual coding / debugging with a second set of (remote) eyes. So thanks to @joshuaulrich for moral support. Adding a handful of lines to take care of Date and Datetime vectors fixes it: ~/git/rcpptoml(master)$ r -lRcppTOML -e'print(parseTOML("/tmp/datebug.toml"))'
List of 2
$ another:List of 2
..$ datetime : POSIXct[1:1], format: "2017-03-17 14:09:00"
..$ datetime_array: POSIXct[1:3], format: "2017-03-17 09:09:00" "2017-03-17 09:10:00" "2017-03-17 09:11:00"
$ section:List of 4
..$ date : chr "2017-01-01"
..$ date_array : chr [1:3] "2017-01-01" "2017-01-01" "2017-01-01"
..$ date_array_unquoted: Date[1:4], format: "2016-01-01" "2016-01-01" "2016-01-01" "2016-01-01"
..$ date_unqoted : Date[1:1], format: "2016-01-01"
~/git/rcpptoml(master)$ Will commit in a moment; feel free to update to GitHub before this gets to CRAN. |
|
Glad to help. Also don't forget to thank past @eddelbuettel's answers on StackOverflow! ;) |
|
I'd upvote him if I could :) |
|
I noticed you only added code to handle Just thinking defensively. Feel free to ignore. :) |
|
They come in as Rcpp types, and those are " R> as.numeric(Sys.Date())
[1] 17242
R> as.numeric(Sys.Date() + 0.5)
[1] 17242.5
R> At one point in the past I came across uses of intra-daily dates with fractions. That's when |
I'm hitting an issue where depending on whether I put dates into arrays or not I get different object types in R.
Here is my TOML file:
And R code:
Which results in:
as.Date(toml$date_array_unquoted, origin="1970-01-01")will return the right result, but it seems to me that this should be a date vector by default.