Repository navigation
Closed
Description
I have a data set with an invalid time stamp, someone put in 14:00 PM.
Normally this converts to NA with IDate, but I found that in some instances it throws an error.
Reproducible example:
library(data.table)
v1 = c("07:36:00", "08:26:00", "08:50:00", "07:05:00", "07:37:00", "08:31:00",
"09:41:00", "10:21:00", "11:16:00", "12:05:00", "12:24:00", "12:43:00",
"12:52:00", "14:00:00")
v2 = c("AM", "AM", "AM", "AM", "AM", "AM", "AM", "AM", "AM", "PM", "PM", "PM",
"PM", "PM")
as.ITime(paste(v1, v2), format="%I:%M:%S %p")
paste(v1, v2)
as.IDate(c("03:00:00 AM", "03:00:00 PM", "15:00:00 AM", "14:00:00 PM"), "%I:%M:%S %p")
as.IDate(c("03:00:00 AM", "03:00:00 PM", "14:00:00 PM"), "%I:%M:%S %p")
"14:00:00 PM" == paste(v1, v2)[14]Screen grab of what happens when I run the above example:

Session Info:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.9.6
loaded via a namespace (and not attached):
[1] chron_2.3-47Also..
Strangely if the vectors are inside a data.table, the data.table will let me convert the vectors to an IDate without an error, but then it won't let me use the data.table. The data table now has an error.

Activity
geneorama commentedon Sep 23, 2015
I think I found the underlying problem,

ITimedoesn't likeNAvaluesarunsrinivasan commentedon Sep 23, 2015
Thanks @geneorama, should be fixed now. Please verify.
geneorama commentedon Sep 24, 2015
yes, it's fixed.
Thanks. I looked at the code myself and wasn't sure where to start. Looking at your edits gave me some insight into S3 methods and some strategies for debugging.
This has helped me realize that can
Previously I believed (in error) that data.table was using so much C code that I wouldn't be able to follow the source.
Next time you'll probably get more detail from me in the issue, perhaps with a code sample.
As always, I appreciate your hard work. Thanks.