Skip to content

IDate Error #1354

Closed
Closed

Description

@geneorama

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:
image

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-47

Also..
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.

v1 and v2 inside a data.table
image

Activity

  1. added this to the v1.9.8 milestone on Sep 22, 2015
  2. geneorama commented on Sep 23, 2015

    @geneorama
    Author

    I think I found the underlying problem, ITime doesn't like NA values
    image

  3. arunsrinivasan commented on Sep 23, 2015

    @arunsrinivasan
    Member

    Thanks @geneorama, should be fixed now. Please verify.

  4. geneorama commented on Sep 24, 2015

    @geneorama
    Author

    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

    1. clone the project,
    2. source the functions where the error is probably happening, and
    3. debug the a copy of the function in my global environment.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions